smart-id-validator
Version:
A package to validate official document numbers and other IDs format for various countries.
33 lines (29 loc) • 1.2 kB
text/typescript
import { CNICValidationResult, PasspostValidateResult, PhoneValidationResult } from './validators/common';
import { validatePhoneNumberPK, validateCNICPK, validatePassportPK } from './validators/PK';
export function validatePhoneNumber(phoneNumber: string, country: string): PhoneValidationResult {
switch (country.toLowerCase()) {
case 'pk':
return validatePhoneNumberPK(phoneNumber);
// Add cases for other countries here
default:
throw new Error(`Unsupported country: ${country}`);
}
}
export function validateCNIC(cnic: string, country: string): CNICValidationResult {
switch (country.toLowerCase()) {
case 'pk':
return validateCNICPK(cnic);
// Add cases for other countries here
default:
throw new Error(`Unsupported country: ${country}`);
}
}
export function validatePassport(passport: string, country: string): PasspostValidateResult {
switch (country.toLowerCase()) {
case 'pk':
return validatePassportPK(passport);
// Add cases for other countries here
default:
throw new Error(`Unsupported country: ${country}`);
}
}