coder coder - 3 months ago 9
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

It might be easier just to upper case the input:

/YOUR_REGEX/.test(yourInput.toUpperCase());

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

/YOUR_REGEX/i.test(yourInput);

Example:

console.log(/[A-Z]+/i.test('abc'))

Comments