Brian Garcia Brian Garcia - 5 months ago 27
Javascript Question

jQuery Validate Regex Case Insensitive

I understand (?i) would make my regex case insensitive, but I am unsure on where to place it. I've already wasted sometime trying to figure this out. Any help is greatly appreciated.

I am using the jQuery Validate plugin for emails, right now if I use a capital it flags it as invalid.

jQuery.validator.addMethod("myEmail", function(value, element) {
return this.optional( element ) || ( /^[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/.test( value ) && /^(?=.{1,64}@.{4,64}$)(?=.{6,100}$).*/.test( value ) );
}, 'Please enter valid email address.');

Answer

Add modifier i and in JavaScript regex modifiers are at the end after /

/^[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/i
Comments