Regular Expression to validate UK National Insurance Number

后端 未结 8 1218
谎友^
谎友^ 2020-12-24 03:05

I have the following regular expression which validates the British National Insurance Number

^([a-zA-Z]){2}( )?([0-9]){2}( )?([0-9]){2}( )?([0-9]){2}( )?([         


        
8条回答
  •  独厮守ぢ
    2020-12-24 03:18

    [RegularExpression(@"^([ACEHJLMOPRSWXYacehjlmoprswxy][A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z]|Bb[A-CEHJ-NPR-TW-Za-cehj-npr-tw-z]|Gg[ACEGHJ-NPR-TW-Zaceghj-npr-tw-z]|[KTkt][A-CEGHJ-MPR-TW-Za-ceghj-mpr-tw-z]|Nn[A-CEGHJL-NPR-SW-Za-ceghjl-npr-sw-z]|Zz[A-CEGHJ-NPR-TW-Ya-ceghj-npr-tw-y])[0-9]{6}[A-Da-d ]$", ErrorMessage = "NI Number must be in the correct format.")]
    
    • N.B/ This will allow users to enter in lower case values, as you may have a style on your textbox to transform lower case to upper case in which case you may want your regex for NI Number to allow lower case aswell.

提交回复
热议问题