Tuesday, 3 October 2017

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










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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...