Kamis, 14 Mei 2009

skrip form validasi

<html>
<body>

<script language="t;JavaScript"t;>

function chkuname()
{
uname=new String();
uname=document.regis.uname.value
if ( uname.length == 0 )
{
alert ("t;Enter a User Name"t;);
}
else
{
chkupass()
}
}

function chkupass()
{
upass=new String();
upass=document.regis.upass.value
if (upass.length < 5)
{
alert ("t;Password Must be atleast 6 Chars"t;);
}
else
{
chkname()
}
}

function chkname()
{
var ch=0;
name=new String();
name=document.regis.name.value;

if (name.length==0)
alert ("t;Enter your Name"t;)
else
{
u=0;
for (i=0;i<name.length;i++)
{
if ((name.charCodeAt(i) >= 64 && name.charCodeAt(i) <= 90)||(name.charCodeAt(i) >=

97 && name.charCodeAt(i) <= 122)||(name.charCodeAt(i)==46)||(name.charCodeAt(i)==32))
{
}
else
{
u=u+1;
}
}
if (u>0)
{
alert ("t;Invalid Name"t;);
}
else
{
chkdob()
}
}
}

function chkdob()
{
dob=new String();

dob=document.regis.dob.value
if (dob.length!=10)
alert ("t;Invalid Date"t;)
else
{
if (dob.charAt(2)!="t;/"t; && dob.charAt(5)!="t;/"t;)
alert ("t;Invalid Date Format"t;)
else
tempstr=dob.split("t;/"t;)
dd=tempstr[0]
mm=tempstr[1]
yy=tempstr[2]
if (dd>=1 && dd<=31 && mm>=1 && mm<=12 && yy>=1900 && yy<=2004 )
{
chkemail()
}
else
alert ("t;Enter Valid date"t;)
}
}

function chkemail()
{
mail=new String();
mail=document.regis.email.value

if (mail.length<1)
alert("t;Please enter e-mail address."t;);
else
{
at_pos=mail.indexOf("t;@"t;)
dot_pos=mail.indexOf("t;."t;)
if(at_pos<1 || dot_pos<1)
alert("t;Missing '@' and '.' in email address."t;)

else
{
u=0;
p=0;
for(var i=0;i<mail.length;i++)
{
if ((mail.charCodeAt(i) >= 64 && mail.charCodeAt(i) <= 90)||(mail.charCodeAt(i) >=

97 && mail.charCodeAt(i) <= 122)||(mail.charCodeAt(i) >= 48 && mail.charCodeAt(i)

<= 57)||(mail.charCodeAt(i)==95)||(mail.charCodeAt(i)==46))
{
if(mail.charAt(i)=="t;@"t;)
p=p+1
}
else
{
u=u+1
}
}
if (p>1)
alert ("t;Email must have only one '@'"t;)
if (u>0)
alert ("t;Special Characters are not allowed"t;)
}
}
}

</script>

<form name="t;regis"t;>
User Name : <input type="t;text"t; name="t;uname"t;

size="t;20"t;>
<br>
Password : <input type="t;password"t; name="t;upass"t;

size="t;20"t;>
<br>
Name : <input type="t;text"t; name="t;name"t; size="t;20"t;>
<br>
DOB (DD/MM/YYYY): <input type="t;text"t; name="t;dob"t;

size="t;8"t;>
<br>
Email : <input type="t;text"t; name="t;email"t; size="t;20"t;>
<br>
<input type="t;button"t; value="t;Submit"t;

onclick="t;chkuname()"t; name="t;sub"t;>
</form>
</body>
</html>

Tidak ada komentar: