Stephane
Stephane

Reputation: 79

Regex and jQuery: lower case

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?

Upvotes: 2

Views: 742

Answers (1)

Samuel Neff
Samuel Neff

Reputation: 74899

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.

Upvotes: 3

Related Questions