Email validator

前端 未结 4 2008
北荒
北荒 2021-01-22 12:20

Having troubles with my email validation code. I keep on getting the error that my function is not defined. i have made a javascript file for the java code and then i used the o

4条回答
  •  我在风中等你
    2021-01-22 13:13

    Email validation is not always as simple as your regular expression. Have you looked at:

    Validate email address in JavaScript?

    A better option would be to use Verimail.js. It's a simple script that takes care of it for you. With Verimail.js you could just do:

    var email = "cool@fabeook.cmo";
    var verimail = new Comfirm.AlphaMail.Verimail();
    
    verimail.verify(email, function(status, message, suggestion){
        if(status < 0){
            // Incorrect syntax!
        }else{
            // Syntax looks great!
        }
    });
    

    The above example will hit the line 'Incorrect syntax!' because of the invalid TLD 'cmo'. Besides this, it will also give a suggestion that you can return to your user, in this case, the suggestion variable will contain 'cool@facebook.com' since 'fabeook.cmo' looks a lot like 'facebook.com'.

    Hope this helps!

提交回复
热议问题