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,570
  • 9
  • 52
  • 78
masacenje
  • 177
  • 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
  • 141,205
  • 29
  • 278
  • 318