Search code examples
c#asp.net-coreunobtrusive-validation

Is There A Way to Make Regex Case Insensitive With JQuery.Validate.Unobtrusive?


I am using .NET Core's client side validation to validate user input based on a regular expression.

The following is a regular expression that accepts 3 letters 'AAA' and 7 digits:

data-val-regex-pattern="^AAA\d{7}\b"

I want to make it case insensitive, so the user can type 'AAA' or 'aaa' and get the same result, but cannot find a way to do so.

I have tried:

  1. Changing the regex to ^(?i)AAA\d{7}\b
  2. Changing the regex to /^AAA\d{7}\b/i
  3. Using | to check multiple expressions, one upper and one lower case.

But nothing has worked.

Can anyone please explain how to make an unobtrusive JavaScript regex case insensitive?


Solution

  • This regex should match the stated criteria: ^[A-Za-z]{3}\d{7}\b

    Can you provide some example data of what should and shouldn't be matched to confirm?

    Great explanation of the pattern courtesy of RegEx101:

    enter image description here