CNIC
import { validateCNIC, getCNICInfo } from 'pakdatakit/cnic'
Checks the structure of a 13-digit Computerised National Identity Card number, and reads the two facts the number itself encodes: the province where it was first registered and the holder’s gender.
validateCNIC() Valid
- Formatted
- 35202-1234567-1
- Province
- Punjab
- Gender
- Male
Examples
Section titled “Examples”import { validateCNIC, getCNICInfo } from 'pakdatakit';
validateCNIC('35202-1234567-1');// → true
validateCNIC('05202-1234567-1');// → false
getCNICInfo('35202-1234567-1');// → {// "digits": "3520212345671",// "formatted": "35202-1234567-1",// "province": "Punjab",// "gender": "male"// }from pakdatakit import validate_cnic, get_cnic_info
validate_cnic('35202-1234567-1')# → True
validate_cnic('05202-1234567-1')# → False
get_cnic_info('35202-1234567-1')# → {# "digits": "3520212345671",# "formatted": "35202-1234567-1",# "province": "Punjab",# "gender": "male"# }import 'package:pakdatakit/pakdatakit.dart';
validateCNIC('35202-1234567-1');// → true
validateCNIC('05202-1234567-1');// → false
getCNICInfo('35202-1234567-1');// → {// "digits": "3520212345671",// "formatted": "35202-1234567-1",// "province": "Punjab",// "gender": "male"// }using PakDataKit;
Cnic.Validate("35202-1234567-1");// → true
Cnic.Validate("05202-1234567-1");// → false
Cnic.GetInfo("35202-1234567-1");// → {// "digits": "3520212345671",// "formatted": "35202-1234567-1",// "province": "Punjab",// "gender": "male"// }use PakDataKit\Cnic;
Cnic::validate('35202-1234567-1');// → true
Cnic::validate('05202-1234567-1');// → false
Cnic::getInfo('35202-1234567-1');// → {// "digits": "3520212345671",// "formatted": "35202-1234567-1",// "province": "Punjab",// "gender": "male"// }Reference
Section titled “Reference”validateCNIC()
Section titled “validateCNIC()”function validateCNIC(cnic: string): boolean;Parameters. cnic: 13 digits, plain or grouped 5-7-1 with hyphens, en dashes, spaces or dots. Urdu digits are accepted.
Returns true when the number has the right shape and starts with a province code from 1 to 8; otherwise false. It never throws.
Caveats. NADRA does not publish a check-digit algorithm, so the last digit is not verified. Separators are only accepted between the 5-7-1 groups.
Related: getCNICInfo(), the CNIC checker.
getCNICInfo()
Section titled “getCNICInfo()”function getCNICInfo(cnic: string): CNICInfo | null;
interface CNICInfo { digits: string; // 13 digits formatted: string; // 35202-1234567-1 province: string; // where the CNIC was first registered gender: 'male' | 'female';}Parameters. cnic: as for validateCNIC().
Returns the decoded parts, or null when the CNIC is not valid.
Caveats. The province is where the CNIC was first registered, not necessarily where the holder lives now. Gender comes from the last digit: odd for male, even for female.
Related: validateCNIC(), formatCNICInput() for as-you-type fields.