Regular Expression to validate Sri Lankan National Identity Card numbers
I crafted a Regular Expression for Sri Lankan phone numbers before, and here is one to validate Sri Lankan National Identify Card numbers.
Legacy 9-digit numbers
- 9 digits followed by an English character
- 11 digits followed by an English character
The linked Wikipedia articles explains the parsing approach.
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.