RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-DFM]{0,1}$
Description
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.
Matches
JG103759A | AP019283D | ZX047829C
Non-Matches
DC135798A | FQ987654C | KL192845T
Author Rating: Not yet rated. Chris Wicks
Source Builds on Peter Whyte's version (http://www.regexlib.com/REDetails.aspx?regexp_id=228)
Your Rating
Bad Good

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: Final character is NOT optional
Name: Constance Reader
Date: 10/12/2012 5:32:52 AM
Comment:
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 optional
Name: Constance Reader
Date: 10/12/2012 4:56:08 AM
Comment:
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 optional
Name: Constance Reader
Date: 10/12/2012 4:29:04 AM
Comment:
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 optional
Name: Constance Reader
Date: 10/12/2012 4:26:32 AM
Comment:
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 optional
Name: Constance Reader
Date: 10/12/2012 4:26:09 AM
Comment:
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: "N" is permitted as first character
Name: Paul Russell
Date: 8/30/2011 12:42:44 PM
Comment:
^[A-CEGHJ-NPR-TW-Za-ceghj-pr-tw-z]{1}[A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z]{1}[0-9]{6}[A-DFMa-dfm]{1}$


Title: "N" is permitted as first character
Name: Paul Russell
Date: 8/30/2011 12:37:55 PM
Comment:
^[A-CEGHJ-NPR-TW-Za-ceghj-pr-tw-z]{1}[A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z]{1}[0-9]{6}[A-DFMa-dfm]{1}$


Title: "N" is permitted as first character
Name: Paul Russell
Date: 8/30/2011 12:37:10 PM
Comment:
^[A-CEGHJ-NPR-TW-Za-ceghj-pr-tw-z]{1}[A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z]{1}[0-9]{6}[A-DFMa-dfm]{1}$


Title: Case change
Name: Michael Barclay
Date: 6/11/2010 10:17:17 AM
Comment:
^[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: HMRC Version
Name: Greatness
Date: 2/18/2010 8:18:39 AM
Comment:
Simon is correct, NINO validations should match what HMRC says it is -- http://www.hmrc.gov.uk/MANUALS/nimmanual/nim39110.htm


Title: HMRC Version
Name: Greatness
Date: 2/18/2010 8:10:27 AM
Comment:
Simon is correct, NINO validations should match what HMRC says it is -- http://www.hmrc.gov.uk/MANUALS/nimmanual/nim39110.htm


Title: Upper and lower case
Name: Stephen D
Date: 12/3/2009 8:08:19 AM
Comment:
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 no
Name: breenbob
Date: 11/4/2009 6:19:25 AM
Comment:
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 Version
Name: Simon
Date: 9/11/2009 12:14:34 PM
Comment:
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 Version
Name: Simon
Date: 9/11/2009 12:14:06 PM
Comment:
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: dfg
Name: dfgdfg
Date: 3/6/2008 5:29:48 AM
Comment:
dfgdfgdf


Title: Needs to allow for spaces
Name: Neil
Date: 4/27/2007 9:19:04 AM
Comment:
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: broken
Name: Rob
Date: 8/26/2005 4:16:42 AM
Comment:
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.


Copyright © 2001-2014, RegexAdvice.com | ASP.NET Tutorials