NI Number Validation
From TekiWiki
This whole wiki has now moved to http://www.springboardsolutions.com/wiki
Go to this page NI Number Validation
| 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> | <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> | </pre> | ||
| Line 109: | Line 110: | ||
</pre> | </pre> | ||
| - | If you need to be this precise, the regular expression is simpler, but longer (the administrative prefixes removed): | + | 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> | <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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C|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> | </pre> | ||
| + | It should be noted that this expression would need to be updated with new prefixes as they are introduced by HMRC. | ||
| + | |||
==Summary== | ==Summary== | ||
| Line 121: | Line 131: | ||
The key validation for current employee payroll NI Numbers would be: | The key validation for current employee payroll NI Numbers would be: | ||
<pre> | <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> | </pre> | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
Try out your regular expressions on the regular expression calculator: [http://www.homemarketeer.com/sbs/regular_expression.html Regular Expression Calculator] | Try out your regular expressions on the regular expression calculator: [http://www.homemarketeer.com/sbs/regular_expression.html Regular Expression Calculator] | ||