The official National Insurance Number Specification states that a valid National Insurance Number conforms to seven rules:
- Must be 9 characters.
- First 2 characters must be alpha.
- Next 6 characters must be numeric.
- Final character can be A, B, C, D or space.
- First character must not be D,F,I,Q,U or V
- Second characters must not be D, F, I, O, Q, U or V.
- First 2 characters must not be combinations of GB, NK, TN or ZZ (the term combinations covers both GB and BG etc.)
If you want users of your site to supply their NI number, you can ensure that they can only enter a valid one by doing the following.
Add a Single Line Text item and add the following, exactly as shown, to the Parameters box:
^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z][0-9]{6}[ABCD ]?$
If you want your users to have the option to enter spaces in between the sections of the number, add the following text to the Parameters box:
^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z] ?([0-9]{2} ?){3} ?[ABCD ]?$
If you want to force your users to put spaces between the sections of the number, add the following text to the Parameters box:
^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z] ([0-9]{2} ){3} [ABCD ]?$
Note that these do not validate for rule 7.
If you just want to verify that the user has entered 2 letters, 6 numbers and a single letter, use:
^[A-Z]{2}[0-9]{6}[A-Z]$
With optional spaces:
^[A-Z]{2} ?([0-9]{2} ?){3} ?[A-Z]$
With mandatory spaces:
^[A-Z]{2} ([0-9]{2} ){3} [A-Z]$
If you just want to verify that the user has entered 2 letters, 6 numbers and an optional single letter, use:
^[A-Z]{2}[0-9]{6}[A-Z]?$
With optional spaces:
^[A-Z]{2} ?([0-9]{2} ?){3} ?[A-Z]?$
With mandatory spaces:
^[A-Z]{2} ([0-9]{2} ){3} [A-Z]?$
Case insensitive entry
Valid National Insurance numbers must be in uppercase. You can adjust the three parameter strings above to allow your users to enter NI numbers in lower case, if you wish to relax that rule. You can do this by using one of the parameters shown here:
- ^[A-CEGHJ-PR-TW-Za-ceghj-pr-tw-z][A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z][0-9]{6}[ABCDabcd ]?$
- ^[A-Za-z]{2}[0-9]{6}[A-Za-z]$
- ^[A-Za-z]{2}[0-9]{6}[A-Za-z]?$
With Optional Spaces:
- ^[A-CEGHJ-PR-TW-Za-ceghj-pr-tw-z][A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z] ?([0-9]{2} ?){3} ?[ABCDabcd ]?$
- ^[A-Za-z]{2} ?([0-9]{2} ?){3} ?[A-Za-z]$
- ^[A-Za-z]{2} ?([0-9]{2} ?){3} ?[A-Za-z]?$
With Mandatory Spaces:
- ^[A-CEGHJ-PR-TW-Za-ceghj-pr-tw-z][A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z] ([0-9]{2} ){3} [ABCDabcd ]?$
- ^[A-Za-z]{2} ([0-9]{2} ){3} [A-Za-z]$
- ^[A-Za-z]{2} ([0-9]{2} ){3} [A-Za-z]?$