0

I have to valid email address in JavaScript. My method is

function validateEmail(email) 
{
    var re = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;

    return re.test(email);
}

Issue is that Visual Studio is not accepting the Regular Expression and giving error when i run the application. The error is enter image description here

adiga
  • 31,610
  • 8
  • 53
  • 74
Waleed Naveed
  • 1,915
  • 1
  • 21
  • 42

2 Answers2

3

Try escaping @. @@ will render as @

function validateEmail(email) 
{
    var re = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;

    return re.test(email);
}
Wai Ha Lee
  • 8,173
  • 68
  • 59
  • 86
Alex
  • 850
  • 1
  • 10
  • 24
0

Try this regex:

^\w+([.]\w+)*@\w+([.]\w+)+$