NI Number Validation

From TekiWiki

Jump to: navigation, search

This whole wiki has now moved to http://www.springboardsolutions.com/wiki

Go to this page NI Number Validation

 
Line 6: Line 6:
The basic format is AA999999A, and a check for this format would be:
The basic format is AA999999A, and a check for this format would be:
-
 
+
<pre>
[A-Z]{2}[0-9]{6}[A-Z]
[A-Z]{2}[0-9]{6}[A-Z]
-
 
+
</pre>
If you are looking for National Insurance Numbers within some text and want to replace them with dummy text, this simple expression will probably meet your needs and catch some of the more exotic NI format numbers that might also need to be replaced.
If you are looking for National Insurance Numbers within some text and want to replace them with dummy text, this simple expression will probably meet your needs and catch some of the more exotic NI format numbers that might also need to be replaced.
Line 19: Line 19:
The first letter cannot be D, F, I, Q, U or V.
The first letter cannot be D, F, I, Q, U or V.
The second letter cannot be D, F, I, O, Q, U and V.
The second letter cannot be D, F, I, O, Q, U and V.
-
 
+
<pre>
[ABCEGHJ-PR-TW-Z][ABCEGHJ-NPR-TW-Z][0-9]{6}[A-D]
[ABCEGHJ-PR-TW-Z][ABCEGHJ-NPR-TW-Z][0-9]{6}[A-D]
-
 
+
</pre>
Additionally, there are certain combinations of prefix letters that have been used for administrative purposes and so are not assignable to individuals on a payroll:
Additionally, there are certain combinations of prefix letters that have been used for administrative purposes and so are not assignable to individuals on a payroll:
Line 81: Line 81:
We can exclude these administrative prefixes by adding a specific expression for each prefix, e.g. allowing CA, but not allowing CR.
We can exclude these administrative prefixes by adding a specific expression for each prefix, e.g. allowing CA, but not allowing CR.
-
Using each of the exception patterns from the table above, the regular expression to validate employee payroll NI numbers is:
+
Using each of the exception patterns from the table above, the regular expression to validate employee payroll NI numbers is (new lines are to fit page only):
-
 
+
<pre>
-
([ABEGHJ-LORSW-Z][ABCEGHJ-NPRSTW-Z])|(C[ABCEGHJ-NPSTW-Z])|(M[ABCEGHJ-NPRSTX-Z])|(N[ABEGHJ-NPRSTW-Z])|(P[ABCEGHJ-NRSTWX])|(T[ABCEGHJ-MPRSTW-Z])[0-9]{6}[A-D]
+
([ABEGHJ-LORSW-Z][ABCEGHJ-NPRSTW-Z])|(C[ABCEGHJ-NPSTW-Z])
-
 
+
|(M[ABCEGHJ-NPRSTX-Z])|(N[ABEGHJ-NPRSTW-Z])|(P[ABCEGHJ-NRSTWX])
 +
|(T[ABCEGHJ-MPRSTW-Z])[0-9]{6}[A-D]
 +
</pre>
From time to time, HMRC publish the list of prefixes in use. This list gradually grows and so if you need this level of accuracy, you would need to be update your regular expression each time HMRC need to increase the list. The following list was supplied in the RTI specification (30th September 2011) - note that it contains some administrative prefixes:
From time to time, HMRC publish the list of prefixes in use. This list gradually grows and so if you need this level of accuracy, you would need to be update your regular expression each time HMRC need to increase the list. The following list was supplied in the RTI specification (30th September 2011) - note that it contains some administrative prefixes:
-
 
+
<pre>
AA, AB, AE, AH, AK, AL, AM, AP, AR, AS, AT, AW, AX, AY, AZ  
AA, AB, AE, AH, AK, AL, AM, AP, AR, AS, AT, AW, AX, AY, AZ  
BA, BB, BE, BH, BK, BL, BM, BT
BA, BB, BE, BH, BK, BL, BM, BT
Line 94: Line 96:
GY
GY
HA, HB, HE, HH, HK, HL, HM, HP, HR, HS, HT, HW, HX, HY, HZ
HA, HB, HE, HH, HK, HL, HM, HP, HR, HS, HT, HW, HX, HY, HZ
-
JA, JB, JC, JE, JG, JH, JJ, JK, JL, JM, JN, JP, JR, JS, JT, JW, JX, JY, JZ
+
JA, JB, JC, JE, JG, JH, JJ, JK, JL, JM, JN, JP, JR, JS, JT, JW,  
 +
JX, JY, JZ
KA, KB, KE, KH, KK, KL, KM, KP, KR, KS, KT, KW, KX, KY, KZ
KA, KB, KE, KH, KK, KL, KM, KP, KR, KS, KT, KW, KX, KY, KZ
LA, LB, LE, LH, LK, LL, LM, LP, LR, LS, LT, LW, LX, LY, LZ
LA, LB, LE, LH, LK, LL, LM, LP, LR, LS, LT, LW, LX, LY, LZ
Line 102: Line 105:
PA, PB, PC, PE, PG, PH, PJ, PK, PL, PM, PN, PP, PR, PS, PT, PW, PX, PY  
PA, PB, PC, PE, PG, PH, PJ, PK, PL, PM, PN, PP, PR, PS, PT, PW, PX, PY  
RA, RB, RE, RH, RK, RM, RP, RR, RS, RT, RW, RX, RY, RZ
RA, RB, RE, RH, RK, RM, RP, RR, RS, RT, RW, RX, RY, RZ
-
SA, SB, SC, SE, SG, SH, SJ, SK, SL, SM, SN, SP, SR, SS, ST, SW, SX, SY ,SZ  
+
SA, SB, SC, SE, SG, SH, SJ, SK, SL, SM, SN, SP, SR, SS, ST, SW,  
 +
SX, SY ,SZ  
TA, TB, TE, TH, TK, TL, TM, TP, TR, TS, TT, TW, TX, TY, TZ
TA, TB, TE, TH, TK, TL, TM, TP, TR, TS, TT, TW, TX, TY, TZ
WA, WB, WE, WK, WL, WM, WP
WA, WB, WE, WK, WL, WM, WP
YA, YB, YE, YH, YK, YL, YM, YP, YR, YS, YT, YW, YX, YY, YZ
YA, YB, YE, YH, YK, YL, YM, YP, YR, YS, YT, YW, YX, YY, YZ
ZA, ZB, ZE, ZH, ZK, ZL, ZM, ZP, ZR, ZS, ZT, ZW, ZX, ZY
ZA, ZB, ZE, ZH, ZK, ZL, ZM, ZP, ZR, ZS, ZT, ZW, ZX, ZY
 +
</pre>
 +
If you need to be this precise, the regular expression is simpler, but longer (the administrative prefixes removed, new lines added purely to fit the page):
 +
<pre>
 +
(AA|AB|AE|AH|AK|AL|AM|AP|AR|AS|AT|AW|AX|AY|AZ|BA|BB|BE|BH|BK|BL|BM|BT
 +
|CA|CB|CE|CH|CK|CL|EA|EB|EE|EH|EK|EL|EM|EP|ER|ES|ET|EW|EX|EY|EZ|GY
 +
|HA|HB|HE|HH|HK|HL|HM|HP|HR|HS|HT|HW|HX|HY|HZ
 +
|JA|JB|JC|JE|JG|JH|JJ|JK|JL|JM|JN|JP|JR|JS|JT|JW|JX|JY|JZ
 +
|KA|KB|KE|KH|KK|KL|KM|KP|KR|KS|KT|KW|KX|KY|KZ
 +
|LA|LB|LE|LH|LK|LL|LM|LP|LR|LS|LT|LW|LX|LY|LZ|MA|MX
 +
|NA|NB|NE|NH|NL|NM|NP|NR|NS|NW|NX|NY|NZ
 +
|OA|OB|OE|OH|OK|OL|OM|OP|OR|OS|OX
 +
|PA|PB|PC|PE|PG|PH|PJ|PK|PL|PM|PN|PR|PS|PT|PW|PX
 +
|RA|RB|RE|RH|RK|RM|RP|RR|RS|RT|RW|RX|RY|RZ
 +
|SA|SB|SC|SE|SG|SH|SJ|SK|SL|SM|SN|SP|SR|SS|ST|SW|SX|SY|SZ
 +
|TA|TB|TE|TH|TK|TL|TM|TP|TR|TS|TT|TW|TX|TY|TZ|WA|WB|WE|WK|WL|WM|WP
 +
|YA|YB|YE|YH|YK|YL|YM|YP|YR|YS|YT|YW|YX|YY|YZ
 +
|ZA|ZB|ZE|ZH|ZK|ZL|ZM|ZP|ZR|ZS|ZT|ZW|ZX|ZY)[0-9]{6}[A-D]
 +
</pre>
 +
It should be noted that this expression would need to be updated with new prefixes as they are introduced by HMRC.
-
If you need to be this precise, the regular expression is simpler, but longer (the administrative prefixes removed):
+
==Summary==
-
 
+
-
(AA|AB|AE|AH|AK|AL|AM|AP|AR|AS|AT|AW|AX|AY|AZ|BA|BB|BE|BH|BK|BL|BM|BT|CA|CB|CE|CH|CK|CL|EA|EB|EE|EH|EK|EL|EM|EP|ER|ES|ET|EW|EX|EY|EZ|GY|HA|HB|HE|HH|HK|HL|HM|HP|HR|HS|HT|HW|HX|HY|HZ|JA|JB|JC|JE|JG|JH|JJ|JK|JL|JM|JN|JP|JR|JS|JT|JW|JX|JY|JZ|KA|KB|KE|KH|KK|KL|KM|KP|KR|KS|KT|KW|KX|KY|KZ|LA|LB|LE|LH|LK|LL|LM|LP|LR|LS|LT|LW|LX|LY|LZ|MA|MX|NA|NB|NE|NH|NL|NM|NP|NR|NS|NW|NX|NY|NZ|OA|OB|OE|OH|OK|OL|OM|OP|OR|OS|OX|PA|PB|PC|PE|PG|PH|PJ|PK|PL|PM|PN|PR|PS|PT|PW|PX|RA|RB|RE|RH|RK|RM|RP|RR|RS|RT|RW|RX|RY|RZ|SA|SB|SC|SE|SG|SH|SJ|SK|SL|SM|SN|SP|SR|SS|ST|SW|SX|SY|SZ|TA|TB|TE|TH|TK|TL|TM|TP|TR|TS|TT|TW|TX|TY|TZ|WA|WB|WE|WK|WL|WM|WP|YA|YB|YE|YH|YK|YL|YM|YP|YR|YS|YT|YW|YX|YY|YZ|ZA|ZB|ZE|ZH|ZK|ZL|ZM|ZP|ZR|ZS|ZT|ZW|ZX|ZY)[0-9]{6}[A-D]
+
-
 
+
-
Summary
+
For simply looking for numbers potentially in NI number format, the following simple expression would suffice:
For simply looking for numbers potentially in NI number format, the following simple expression would suffice:
-
 
+
<pre>
[A-Z]{2}[0-9]{6}[A-Z]
[A-Z]{2}[0-9]{6}[A-Z]
-
 
+
</pre>
The key validation for current employee payroll NI Numbers would be:
The key validation for current employee payroll NI Numbers would be:
 +
<pre>
 +
([ABEGHJ-LORSW-Z][ABCEGHJ-NPRSTW-Z])|(C[ABCEGHJ-NPSTW-Z])
 +
|(M[ABCEGHJ-NPRSTX-Z])|(N[ABEGHJ-NPRSTW-Z])
 +
|(P[ABCEGHJ-NRSTWX])|(T[ABCEGHJ-MPRSTW-Z])[0-9]{6}[A-D]
 +
</pre>
-
([ABEGHJ-LORSW-Z][ABCEGHJ-NPRSTW-Z])|(C[ABCEGHJ-NPSTW-Z])|(M[ABCEGHJ-NPRSTX-Z])|(N[ABEGHJ-NPRSTW-Z])|(P[ABCEGHJ-NRSTWX])|(T[ABCEGHJ-MPRSTW-Z])[0-9]{6}[A-D]
+
Try out your regular expressions on the regular expression calculator:  [http://www.homemarketeer.com/sbs/regular_expression.html Regular Expression Calculator]
-
A slightly longer, but more exact expression would be:
+
Regular expression information: [http://www.homemarketeer.com/sbs/regexp.htm Regular Expression Information]
-
(AA|AB|AE|AH|AK|AL|AM|AP|AR|AS|AT|AW|AX|AY|AZ|BA|BB|BE|BH|BK|BL|BM|BT|CA|CB|CE|CH|CK|CL|EA|EB|EE|EH|EK|EL|EM|EP|ER|ES|ET|EW|EX|EY|EZ|GY|HA|HB|HE|HH|HK|HL|HM|HP|HR|HS|HT|HW|HX|HY|HZ|JA|JB|JC|JE|JG|JH|JJ|JK|JL|JM|JN|JP|JR|JS|JT|JW|JX|JY|JZ|KA|KB|KE|KH|KK|KL|KM|KP|KR|KS|KT|KW|KX|KY|KZ|LA|LB|LE|LH|LK|LL|LM|LP|LR|LS|LT|LW|LX|LY|LZ|MA|MX|NA|NB|NE|NH|NL|NM|NP|NR|NS|NW|NX|NY|NZ|OA|OB|OE|OH|OK|OL|OM|OP|OR|OS|OX|PA|PB|PC|PE|PG|PH|PJ|PK|PL|PM|PN|PR|PS|PT|PW|PX|RA|RB|RE|RH|RK|RM|RP|RR|RS|RT|RW|RX|RY|RZ|SA|SB|SC|SE|SG|SH|SJ|SK|SL|SM|SN|SP|SR|SS|ST|SW|SX|SY|SZ|TA|TB|TE|TH|TK|TL|TM|TP|TR|TS|TT|TW|TX|TY|TZ|WA|WB|WE|WK|WL|WM|WP|YA|YB|YE|YH|YK|YL|YM|YP|YR|YS|YT|YW|YX|YY|YZ|ZA|ZB|ZE|ZH|ZK|ZL|ZM|ZP|ZR|ZS|ZT|ZW|ZX|ZY)[0-9]{6}[A-D]
+
[[PeopleSoft HRMS]] already has built in UK National Insurance validation, but you can use Regular Expressions in PeopleSoft - [[PeopleSoft Regular Expressions]]
-
 
+
-
It should be noted that this expression would need to be updated with new prefixes as they are introduced by HMRC.
+

Latest revision as of 17:11, 11 August 2013

Personal tools