Regular Expressions 101

Community Patterns

Sri Lankan NIC Validation Regex - Sri Lanka - National Identity Card Number Validation Regex

1

Regular Expression
PCRE2 (PHP >=7.3)

/
^(([5,6,7,8,9]{1})([0-9]{1})([0,1,2,3,5,6,7,8]{1})([0-9]{6})([v|V|x|X]))|(([1,2]{1})([0,9]{1})([0-9]{2})([0,1,2,3,5,6,7,8]{1})([0-9]{7}))
/
gm

Description

Extract the Data from Sri Lankan National Identity Card

The SL NIC could be divided into two groups,

  1. Before 2016 (9 alphanumeric digits with one English letter)
  2. After 2016 (12 alphanumeric digits)

NICs issued before 1 January 2016, each NIC has a unique 9-digit number and a letter, in the format 000000000V (where 0 is a digit and V is a letter). The first two digits of the number are the holder's year of birth (e.g.: 91xxxxxxxx for someone born in 1991). The next three digits contain the number of the day in the year for the person's birth. For females, 500 is added to the number of days. The next three digits number is the serial number of the issued day. The next digit is the check digit. The final letter is generally a 'V' which indicates that the holder is eligible to vote in the area. In some cases the final letter can be 'X' which usually indicates the holder is not eligible to vote; possibly because they were not permanent residents of Sri Lanka when applying for a NIC. (Directly copied from Wikipedia)

  1. Old NIC - Before 2016

Birth Year: 72 Day Count for Birthday: 244 Serial Number; 152 Check Digit: 4 Special Letter: V

The NIC Number: 722441524V

  1. New NIC - After 2016

Birth Year: 2001 Day Count for Birthday: 253 Serial Number; 0297 Check Digit: 6 Special Letter: -

The NIC Number: 200125302976

  • Can be used for any men or women born in 1950-2999
Submitted by Aadhil Ahamed (Find me on GitHub: https://github.com/AadhilMR) - a year ago