0

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.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
coder
  • 23
  • 1
  • 9

1 Answers1

1

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'))
Rob M.
  • 35,491
  • 6
  • 51
  • 50