Email validation using jQuery Email validation using jQuery jquery jquery

Email validation using jQuery


You can use regular old javascript for that:

function isEmail(email) {  var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;  return regex.test(email);}


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})?$/;  return emailReg.test( $email );}

and now to use this

if( !validateEmail(emailaddress)) { /* do stuff here */ }

Cheers!


I would use the jQuery validation plugin for a few reasons.

You validated, ok great, now what? You need to display the error, handle erasing it when it is valid, displaying how many errors total perhaps? There are lots of things it can handle for you, no need to re-invent the wheel.

Also, another huge benefit is it's hosted on a CDN, the current version at the time of this answer can be found here: http://www.asp.net/ajaxLibrary/CDNjQueryValidate16.ashx This means faster load times for the client.