简体   繁体   中英

Valid email address in JavaScript using RegularExpression

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 在此处输入图片说明

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);
}

试试这个正则表达式:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM