Ayesh Karunaratne: Full-time traveler, freelance software architect and security researcher
Wed, 2019-02-13 16:51
I crafted a Regular Expression for Sri Lankan phone numbers before, and here is one to validate Sri Lankan National Identify Card numbers.
Requires a modern browser with ES2018 Regex support due to negative look-behinds.
NIC numbers have 2 formats:
- 9 digits followed by an English character
- 11 digits followed by an English character
Pretty much everyone knows how the number is calculated, so I'm not going to explain it for the n+1-th time.
The above regex:
- Validates both new and old NIC number formats
- Correctly validates birth year to be in current or the last century
- Validates the possible number range for both male and female numbers (do not blame me for binary genders)
- Validates the last English letter, where it must be one of
xthat indicates the NIC holder is allowed to vote or not, respectively.