Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email validation using jQuery

I'm new to jQuery and was wondering how to use it to validate email addresses.

like image 533
DuH Avatar asked Mar 24 '10 10:03

DuH


People also ask

How to validation email in jQuery?

Approach: You can validate Email using jQuery by using the regex pattern. Regex expression is used for search operation and they are special strings representing a pattern to be matched. Example: HTML.

How do you validate a form?

Basic Validation − First of all, the form must be checked to make sure all the mandatory fields are filled in. It would require just a loop through each field in the form and check for data. Data Format Validation − Secondly, the data that is entered must be checked for correct form and value.


2 Answers

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); } 
like image 71
Fabian Avatar answered Sep 21 '22 06:09

Fabian


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!

like image 39
Manish Shrivastava Avatar answered Sep 23 '22 06:09

Manish Shrivastava