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.
精彩评论