coder coder - 1 year ago 75
Javascript Question

Regular expression to allow lower case

I want to let lower case also as acceptable on my regular expression

[RegularExpression(@"^(?!BG|GB|NK|KN|TN|NT|ZZ)[ABCEGHJ-PRSTW-Z][ABCEGHJ-NPRSTW-Z]\d{6}[A-D]$", ErrorMessage = "Invalid National Insurance Number")]

How to allow lower case

I tried based on some stack flow solution like below

@"(i)^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|

[ABEHMNPRV-Y]))|[0-9][A-HJKPS-UW]) {0,1}[0-9][ABD-HJLNP-UW-Z]{2})$

But it didnt work.

Answer Source

It might be easier just to upper case the input:


You can also turn on case insensitivity with the /i flag in your regex:




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download