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
  • 34,372
  • 9
  • 61
  • 83
Waleed Naveed
  • 2,293
  • 2
  • 29
  • 57

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,598
  • 83
  • 57
  • 92
Alex
  • 878
  • 1
  • 10
  • 25
0

Try this regex:

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