0

I am not expert in JavaScript and need to get this regex to work:

function validateEmail(email) { 
    var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,22}/;
    return re.test(email);
}

Currently this doesn't work fine, even for myemail@hotmail.com.

I don't need a new regex, just few changes to this one to get it to work.

J0e3gan
  • 8,740
  • 10
  • 53
  • 80
masacenje
  • 187
  • 3
  • 12

1 Answers1

4

You need to use the case-insensitive flag, i:

var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,22}/i;

Without this, it would only match upper-case Latin letters, e.g. MYEMAIL@HOTMAIL.COM.

See MDN for a list of supported flags.

p.s.w.g
  • 146,324
  • 30
  • 291
  • 331