开发者

Jquery - Validating Email

I do NOT want to u开发者_运维百科se the Jquery attachment to the field. I just want a function I can call and pass in a value and get back a result on if it is a valid email. JQuery documentation seems to indicate this is possible but the documentation falls short on examples outside of attaching it to the field.

I realize I can use third-party functions, but it would be nice to know how to do this with Jquery since I do this alot in projects.


You should validate the email address properly on the server, and only use a simple regex on the client.

For example:

function isValidEmail(value) { 
    return /.+@.+\..+/.test(value);
}

You can replace the regex with something more sophisticated, but don't get carried away. In particular, make sure you allow a.b+c@gmail.com. (Which many sites sadly and incorrectly reject)

On the server side, you should use a proper, non-regex-based validator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜