Validate
verifyIranianNationalId(nationalId, options?)
Algorithm
- Falsy →
undefined. - Length must be ≥ 8; shorter inputs are zero-padded to 10 (so
499370899is accepted as0499370899). - Reject all-same-digit sequences (
0000000000,1111111111, …) via the exportedinvalidNationalIdSequencesset. - If
checkPrefix !== false, the leading 3 digits must be invalidNationalIdPrefixes. - Standard check-digit computation:
sum = Σ digit[i] * (10 - i)for i = 0..8, thendigit[9]must equalsum % 11(or11 - sum%11ifsum%11 ≥ 2).
Look up the place
For city/province from a National ID’s 3-digit prefix, see the Place by National ID page.Generate (for tests)
Pitfalls
- Persian/Arabic digit input is NOT auto-normalized.
verifyIranianNationalId("۰۴۹۹۳۷۰۸۹۹")returnsfalsebecauseparseIntof Persian digits yieldsNaN. RunautoConvertDigitsToENfirst. - Return type is
boolean | undefined— use=== true, not truthy checks. - For test fixtures, generate IDs with
createIranianNationalId(...). Don’t commit real personal data.
Source
src/modules/nationalId/index.ts, src/modules/nationalId/create-national-id.ts · Tests: test/verifyIranianNationalId.spec.ts