how can i validate email using javascript?


I would like to know how can I validate email using javascript-jquery?


Asked by:- Vipin
1
: 2519 At:- 7/10/2017 8:04:42 AM
javascript jquery email-validation

you can use regex to validate your email id using javascript 1
By : jaya - at :- 7/10/2017 12:36:45 PM
Can you show me code for it? thanks 0
By : Vipin - at :- 7/10/2017 12:39:57 PM






2 Answers
profileImage Answered by:- jaya

You can validate email id using Javascript regex code as below:

function CheckEmailAddress(emailAddress) {
    var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
    return pattern.test(emailAddress);
};

You can call above email validation regex function using code below

if( !CheckEmailAddress( emailaddress ) )
 { 
/* do something */ 
}

Another example here

2
At:- 7/10/2017 12:47:25 PM
thank you for quick reply 0
By : Vipin - at :- 7/10/2017 12:49:50 PM


profileImage Answered by:- vikas_jk

There is another regex to validate email using javascript, which is similar to what @Jaya has posted, here is the code

function CheckEmailAddress(emailAddress) {
    var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);   
    return pattern.test(emailAddress);
};

this is a simpler regex, so it checks less number of variations of email, but still works in simpler cases.

 

0
At:- 7/10/2017 12:53:45 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use