Regular Expression to validate UK National Insurance Number

后端 未结 8 1271
谎友^
谎友^ 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:29

    • Just found this when I was digging around to find a proper regex. So just thought of sharing this DWP NINO format-validation.
    • Under the hood, they are using the following regex "(^(?!BG)(?!GB)(?!NK)(?!KN)(?!TN)(?!NT)(?!ZZ)[A-Z&&[^DFIQUV]][A-Z&&[^DFIOQUV]][0-9]{6}[A-D ]$)"
    • I found this very useful and works as expected older version of maven also supports NINO with ending character as space.
    • List item

    Nino Validator meets all the following criteria.

    • 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.)

提交回复
热议问题