JavaScript Regular Expression Email Validation

This question already has an answer here:

  • How to validate an email address in JavaScript? 69 answers
  • How to validate an email address using a regular expression? 74 answers

  • If you define your regular expression as a string then all backslashes need to be escaped, so instead of 'w' you should have 'w'.

    Alternatively, define it as a regular expression:

    var pattern = /^w+@[a-zA-Z_]+?.[a-zA-Z]{2,3}$/; 
    

    BTW, please don't validate email addresses on the client-side. Your regular expression is way too simple to pass for a solid implementation anyway.

    See the real thing here: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html


    this is the one i am using on my page.

    http://www.zparacha.com/validate-email-address-using-javascript-regular-expression/

    /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,6}$/


    I've been using this function for a while. it returns a boolean value.

    // Validates email address of course.
    function validEmail(e) {
        var filter = /^s*[w-+_]+(.[w-+_]+)*@[w-+_]+.[w-+_]+(.[w-+_]+)*s*$/;
        return String(e).search (filter) != -1;
    }
    
    链接地址: http://www.djcxy.com/p/92560.html

    上一篇: 创建一个依赖多个AAR的AAR

    下一篇: JavaScript正则表达式电子邮件验证