jQuery Email Validation without a Plugin
For updated code check out the fiddle on jsFiddle; Validate Email using jQuery
Validating Email using jQuery
More and more I am finding out that I use jQuery predominately for my projects. Now I keep a local repository of code snippets, but I as I have said in the past I am trying to move all my local code to the “cloud”. I am storing all my code on my website so that I will have even easier access than before and to get traffic to my site.
jQuery Function to Validate Email
I really don’t like to use plugins, especially when my form only has one field that needs to be validated. I use this function and call it whenever I need to validate an email form field.
function validateEmail(email) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if( !emailReg.test( email ) ) {
return false;
} else {
return true;
}
}
Pretty basic here, but I always forget the Regex string. Now I can just copy the snippet from my site!
Looking for help
Does anyone have better code for jquery email validation? I am always trying to get my code to be more secure and more efficient and any help in greatly appreciated.




