Here is a script that checks for the validity of email, avoiding invalid characters, position of @ and . dot and domian name is checked for the well known domains such as .com, .net or else and restricts the user to enter the valid domain name.
Code:
<HTML>
<HEAD>
<META http-equiv="Content-Language" content="en-us">
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<META name="GENERATOR" content="Microsoft FrontPage 4.0">
<META name="ProgId" content="FrontPage.Editor.Document">
<TITLE>EMAIL VALIDATION</TITLE>
<STYLE>
A:link {text-decoration: none; color: #0000ff;}
A:visited {text-decoration: none; color: #ff0000;}
A:active {text-decoration: none; color: #FFff00;}
A:hover {text-decoration: underline; color:#00ffff;}
</STYLE>
<SCRIPT LANGUAGE=JAVASCRIPT>
function checkfield(loginform)
{
ok=true
if(loginform.elements[0].value=="")
{
alert("Please enter e-mail address.")
loginform.elements[0].focus()
ok=false
}
else
{
mail=loginform.elements[0].value
at_pos=mail.indexOf("@")
dot_pos=mail.indexOf(".")
if(at_pos<1 || dot_pos<1)
{
alert("Please check position of '@' and '.' in email address.")
loginform.elements[0].focus()
ok=false
}
else
{
mail=loginform.elements[0].value
condition="yes"
var at_count=0
var dot_count=0
var temp=0
for(var i=0;i<mail.length;i++)
{
if((mail.charCodeAt(i)>0 && mail.charCodeAt(i)<48)||(mail.charCodeAt(i)>57 && mail.charCodeAt(i)<65)||(mail.charCodeAt(i)>91 && mail.charCodeAt(i)<97)||mail.charCodeAt(i)>122)
{
if(mail.charAt(i)=="@"||mail.charAt(i)==".")
{
if(mail.charAt(i)=="@"){at_count++}else{dot_count++} // counts the no. of times @ and . appears in email
if(dot_count>=1)
{
dot_pos=i
if((dot_pos>at_pos) && temp==0)
{
pos=dot_pos-at_pos
temp++
}
}
}
else
{
condition="no"
i=mail.length
}
}
}
if(condition=="no")
{
alert("Your email contains a blank space or special character.")
loginform.elements[0].focus()
ok=false
}
else
{
if(at_count>1)
{
alert("E-mail contains extra @ ")
loginform.elements[0].focus()
ok=false
}
else
{
if(pos<2)
{
alert("Missing domain name between '@' and '.'")
loginform.elements[0].focus()
ok=false
i=mail.length
}
else
{
count=dot_pos+1
domain=""
for(count;count<mail.length;count++)
{
domain=domain+mail.charAt(count)
}
dom=new Array("au","com","net","org","edu","in","mil","gov","arpa","biz","aero","name","coop","info","pro","museum")
error="yes"
for(var k=0;k<dom.length;k++)
{
if(domain==dom[k])
{
k=dom.length
error="no"
}
}
if((error=="yes" && (domain.length>2)) || (domain.length<2))
{
alert("Domain name must end with well known domains \n or 2-lettered country name. eg com,edu,in etc.")
loginform.elements[0].focus()
ok=false
}
}
}
}
}
}
return ok
}
</SCRIPT>
</HEAD>
<BODY text="#000080" bgcolor="#C0C0C0">
<FORM name="loginform" onSubmit="return checkfield(loginform)">
<TABLE border="0" width="100%">
<TR>
<TD width="25%"></TD>
<TD width="50%" colspan="2">
<P align="center"><B><FONT size="5">EMAIL VALIDATION</FONT></B></TD>
<TD width="25%"></TD>
</TR>
<TR>
<TD width="100%" colspan="4"></TD>
</TR>
<TR>
<TD width="100%" colspan="4"></TD>
</TR>
<TR>
<TD width="100%" colspan="4"></TD>
</TR>
<TR>
<TD width="100%" colspan="4"></TD>
</TR>
<TR>
<TD width="25%" rowspan="3"></TD>
<TD width="15%">Enter your e-mail :</TD>
<TD width="35%"><INPUT name="T1" size="27" tabindex="1"></TD>
<TD width="25%" rowspan="3"></TD>
</TR>
<TR>
<TD width="15%"></TD>
<TD width="35%"></TD>
</TR>
<TR>
<TD width="15%"></TD>
<TD width="35%"><INPUT type="submit" value="Submit" name="B1" tabindex="3"></TD>
</TR>
<TR>
<TD width="100%" colspan="4"></TD>
</TR>
<TR>
<TD width="100%" colspan="4"></TD>
</TR>
<TR>
<TD width="100%" colspan="4" align="center"><B>for more scripts contact : Abhishek Chitransh </B></TD>
</TR>
<TR>
<TD width="100%" colspan="4" align="center"><B>email: <A href="mailto:abhishekc.in@gmail.com">abhishekc.in@gmail.com</A></B></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
No comments:
Post a Comment