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

2 Answers

3
JasonA On Best Solutions

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);
}
0
ut or On

Try this regex:

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