Advertise with us

Sponsors

Regular Expression Details

UK National Insurance Number (NINo) validation. The following modifications have been made: The first letter may not be D, F, I, Q, U or Z; the second letter may not be D, F, I, O, Q, U or Z; the final letter is optional.

Builds on Peter Whyte's version (http://www.regexlib.com/REDetails.aspx?regexp_id=228)

Your Rating

Bad12345Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Don't use the above regexName: JoeDate: 3/22/2016 6:45:14 AMComment: As Simon mentioned the original regex is wrong for a number of reasons and should not be used. Below is better but doesn't check for administration numbers.
^[ABCEGHJKLMNOPRSTWXYZabceghjklmnoprstwxyz][ABCEGHJKLMNPRSTWXYZabceghjklmnprstwxyz][0-9]{6}[A-D\sa-d]{0,1}$
Useful links.
http://www.hmrc.gov.uk/schemas/core-v2-0.xsd
http://www.hexcentral.com/articles/validate_ni.htm
http://www.hmrc.gov.uk/MANUALS/nimmanual/nim39110.htm
Best Regards,
Joe

Title: Final character is NOT optionalName: Constance ReaderDate: 10/12/2012 5:32:52 AMComment: It's not completely correct to say "the final letter is optional". The NINO is always exactly nine characters. The last one is either a letter or a space, but is always present. In other words, if the letter is absent, you can't trim the number back to eight characters.
Source: http://webarchive.nationalarchives.gov.uk/+/http://www.cabinetoffice.gov.uk/govtalk/schemasstandards/e-gif/datastandards/identifiers/national_insurance_number.aspx (points 1 and 4).
Another useful reference: http://www.hexcentral.com/articles/validate_ni.htm
Also, the use of F or M as the final character is now deprecated. Although some NINOs still exist with these suffixes, they will be rejected in electronic submissions.

Title: Final character is NOT optionalName: Constance ReaderDate: 10/12/2012 4:56:08 AMComment: It's not completely correct to say "the final letter is optional". The NINO is always exactly nine characters. The last one is either a letter or a space, but is always present. In other words, if the letter is absent, you can't trim the number back to eight characters.
Source: http://webarchive.nationalarchives.gov.uk/+/http://www.cabinetoffice.gov.uk/govtalk/schemasstandards/e-gif/datastandards/identifiers/national_insurance_number.aspx (points 1 and 4).
Another useful reference: http://www.hexcentral.com/articles/validate_ni.htm
Also, the use of F or M as the final character is now deprecated. Although some NINOs still exist with these suffixes, they will be rejected in electronic submissions.

Title: Final character is NOT optionalName: Constance ReaderDate: 10/12/2012 4:29:04 AMComment: It's not completely correct to say "the final letter is optional". The NINO is always exactly nine characters. The last one is either a letter or a space, but is always present. In other words, if the letter is absent, you can't trim the number back to eight characters.
Source: http://webarchive.nationalarchives.gov.uk/+/http://www.cabinetoffice.gov.uk/govtalk/schemasstandards/e-gif/datastandards/identifiers/national_insurance_number.aspx (points 1 and 4).
Another useful reference: http://www.hexcentral.com/articles/validate_ni.htm
Also, the use of F or M as the final character is now deprecated. Although some NINOs still exist with these suffixes, they will be rejected in electronic submissions.

Title: Final character is NOT optionalName: Constance ReaderDate: 10/12/2012 4:26:32 AMComment: It's not completely correct to say "the final letter is optional". The NINO is always exactly nine characters. The last one is either a letter or a space, but is always present. In other words, if the letter is absent, you can't trim the number back to eight characters.
Source: http://webarchive.nationalarchives.gov.uk/+/http://www.cabinetoffice.gov.uk/govtalk/schemasstandards/e-gif/datastandards/identifiers/national_insurance_number.aspx (points 1 and 4).
Another useful reference: http://www.hexcentral.com/articles/validate_ni.htm
Also, the use of F or M as the final character is now deprecated. Although some NINOs still exist with these suffixes, they will be rejected in electronic submissions.

Title: Final character is NOT optionalName: Constance ReaderDate: 10/12/2012 4:26:09 AMComment: It's not completely correct to say "the final letter is optional". The NINO is always exactly nine characters. The last one is either a letter or a space, but is always present. In other words, if the letter is absent, you can't trim the number back to eight characters.
Source: http://webarchive.nationalarchives.gov.uk/+/http://www.cabinetoffice.gov.uk/govtalk/schemasstandards/e-gif/datastandards/identifiers/national_insurance_number.aspx (points 1 and 4).
Another useful reference: http://www.hexcentral.com/articles/validate_ni.htm
Also, the use of F or M as the final character is now deprecated. Although some NINOs still exist with these suffixes, they will be rejected in electronic submissions.

Title: Case changeName: Michael BarclayDate: 6/11/2010 10:17:17 AMComment: ^[A-CEGHJ-PR-TW-Za-ceghj-pr-tw-z]{1}[A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z]{1}[0-9]{6}[A-DFMa-dfm]{1}$
Although not technically correct that NI numbers could be in lowercase this caters for that scenario, also I believe (from HRM website), you have to have 1 letter at the end

Title: Upper and lower caseName: Stephen DDate: 12/3/2009 8:08:19 AMComment: hey i used the regular expression for the input on a form but my clients have came back and asked could it be converted in to uppercase automatically. i used a style text-transform:uppercase and it does display it all in upper case, however it must still be reading it in as lower case because i still get an error message when i enter with out the caps lock on, despite displaying in upper on the form. how would i edit this expression to include both upper and lower?

Title: NI NI noName: breenbobDate: 11/4/2009 6:19:25 AMComment: I live in Northern Ireland (part of the UK) and my OWN national insurance number starts NI. This makes your second letter rule invalid!

Title: HMRC VersionName: SimonDate: 9/11/2009 12:14:34 PMComment: The HMRC have a schema that can be found at http://www.hmrc.gov.uk/schemas/core-v2-0.xsd
It includes their versions of NINO (as well as many others) that as far as I believe they use to validate submissions against.
Their NINO:
[ABCEGHJKLMNOPRSTWXYZ][ABCEGHJKLMNPRSTWXYZ][0-9]{6}[A-D ]
Might be worth allowing for spaces and splitting up the [0-9]{6} into three lots of [0-2]{2}[\s]{0,1} or similar as per Neil's post.

Title: HMRC VersionName: SimonDate: 9/11/2009 12:14:06 PMComment: The HMRC have a schema that can be found at http://www.hmrc.gov.uk/schemas/core-v2-0.xsd
It includes their versions of NINO (as well as many others) that as far as I believe they use to validate submissions against.
Their NINO:
[ABCEGHJKLMNOPRSTWXYZ][ABCEGHJKLMNPRSTWXYZ][0-9]{6}[A-D ]
Might be worth allowing for spaces and splitting up the [0-9]{6} into three lots of [0-2]{2}[\s]{0,1} or similar as per Neil's post.

Title: dfgName: dfgdfgDate: 3/6/2008 5:29:48 AMComment: dfgdfgdf

Title: Needs to allow for spacesName: NeilDate: 4/27/2007 9:19:04 AMComment: Subject to context you may wish to allow for spaces between the letters and pairs of numbers.
So:
^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}\s?[0-9]{2}\s?[0-9]{2}\s?[0-9]{2}\s?[A-DFM]{0,1}$
Does this. I don't know of an elegant way to repeat \s?[0-9]{2} three times - I'm sure somebody else does!
Re Rob's comment - V is actually not allowed so the regex is correct. Z is allowed. (I'll burn the anorak now)

Title: brokenName: RobDate: 8/26/2005 4:16:42 AMComment: Both parts don't allow 'V' although the description says nothing about 'V' not being allowed. The second part says 'Z' is not allowed, but it is allowed through.