How to validate an Email by javascript in a ASP.NET page..
function ValidateEmail(ctl)
{
var strEmail=null;
var ReturnValue=null;
strEmail= document.getElementById(ctl).value;
strEmail= strEmail.replace( /^\s+/g, "" ); // strip leading
strEmail= strEmail.replace( /\s+$/g, "" ); // strip trailing
var at="@";
var dot=".";
var lat=strEmail.indexOf(at);
var lstr=strEmail.length;
var ldot=strEmail.indexOf(dot);
if (strEmail.indexOf(at)==-1)
{
ReturnValue=0;
}
else if (strEmail.indexOf(at)==-1 || strEmail.indexOf(at)==0 || strEmail.indexOf(at)==lstr)
{
ReturnValue=0;
}
else if (strEmail.indexOf(dot)==-1 || strEmail.indexOf(dot)==0 || strEmail.indexOf(dot)==lstr)
{
ReturnValue=0;
}
else if (strEmail.indexOf(at,(lat+1))!=-1)
{
ReturnValue=0;
}
else if (strEmail.substring(lat-1,lat)==dot || strEmail.substring(lat+1,lat+2)==dot)
{
ReturnValue=0;
}
else if (strEmail.indexOf(dot,(lat+2))==-1)
{
ReturnValue=0;
}
else if (strEmail.indexOf(" ")!=-1)
{
ReturnValue=0;
}
if (ReturnValue=='0') //Not Valid
{
return 0;
}
else //Valid Email
{
return 1;
}
}
Hello Anil
ReplyDeleteIt helped me a lot..
Thanks
thats grateeee.
ReplyDeletei will try to post more codes like thiss