2

I would like to validate my form with jquery validation plugin. I added a method for on input:

$.validator.addMethod("testRegex", function(value, element) {
    return this.optional(element) || /^[a-z0-9-_]+$/i.test(value);
}, "test must contain only letters, numbers, underscores or dashes");

But I want a validation to check if the value is only lowercase. And This validation doesn't work.

Do you have an idea?

Sparky
  • 98,165
  • 25
  • 199
  • 285
Stephane
  • 79
  • 1
  • 7

1 Answers1

3

The i in your regex means ignore case. If you want your regular expression to be case sensitive then remove it.

/^[a-z0-9-_]+$/i

becomes

/^[a-z0-9-_]+$/

No i at end.

Samuel Neff
  • 73,278
  • 17
  • 138
  • 182