Saturday, December 22, 2018

c# - javascript validation for email format accepting incorrect email format @abcd.com.gmail,





Possible Duplicate:
Validate email address in Javascript?






I have to do validation for Email format, I am using the CODE below line to restrict Special Characters.




onkeypress="return AlphaNumericBox(event,this,'@._);"


But now the Problem is I don have any proper validation for the exact format for example its also accepting text like " @abcd.com.gmail,.. " Is there any javascript validation for this?
any idea?



Thanks in advance.


Answer



function CheckEmail(address){
address=address.replace(/(^\s*)|(\s*$)/g, "");

var reg=/([\w._-])+@([\w_-])+(\.([\w_-])+){1,2}/;
var matcharr=reg.exec(address);
if(matcharr!=null){
if(matcharr[0].length==address.length){
return true;
}
return false;
}
return false;
}


eg:
var sVal=" t.st@gmail.com.cn ";
var sVal2=" t.st@gmail.com.cn.abc ";
console.log(CheckEmail("name@server.com")); //outpus true
console.log(CheckEmail("@server.com")); //outpus false

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...