一个注册表单验证的js
这个脚本对你可能有帮助:<script language="javascript">
function IsDigit(cCheck)
{ b!U8VS,X ]2?-M\
return (('0'<=cCheck) && (cCheck<='9')); _!d4Zf8L
} 6i^Z{N[#p5a
%x9n ^d:O
function IsAlpha(cCheck) 3y[.A1J3m%a]
{
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))
}
1|8Z1Jj#iliu
function IsaNull(cCheck)
{ $?|e,s1}
return(cCheck != " ") ~4h/NY gkr
} Bnw!?Y(R
function checkform() }]*|:K@2F^
{ gqb8P7n-ZcT/Y
id = document.sform1.id.value;
if (id == "")
{ ;i,V3Io,`d,l*IW8H
alert("请输入注册名"); *Z,w\tg/g8p
document.sform1.id.focus();
return false;
}
for (nIndex=0; nIndex<id.length; nIndex++) [._ \Pph*K [%u S
{ (d,q.Ce(GQ
cCheck = id.charAt(nIndex); nD"c,~gllE:VPi
if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))
{
alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文"); 2ZB2~ s9v5r]NF
document.sform1.id.focus(); )wM!r8b_ L\:X
return false; 9gd3b W+T Lgg(`
} t R^7|M I ?
} &a6H~9R2x7s
chineseid = document.sform1.chineseid.value; V Z:R]6e y
if (chineseid == "")
{ tI5|n,m9Voyz)m7Y
alert("请输入中文昵称");
document.sform1.chineseid.focus();
return false;
} b(DX&Z0Pe o[
password = document.sform1.password.value;
if (password == "")
{ a%?shx5| N
alert("请输入登陆密码");
document.sform1.password.focus(); N3\6Ur'~:X
return false; hIa;w+ss3x
}
password1 = document.sform1.password1.value; T(I;b4y-K[;K~
if (password>password1) 3m#k @'q^^4S_ x R
{"_DB#\Y@+`|&md){
alert("重复密码与登陆密码不相同"); kBzY#UJd4L/f
document.sform1.password.focus(); &x+~B,^6MF
document.sform1.password1.focus();
return false;
} f g nkm!qk"`0WH
if (password<password1) %t%s!cP^e
{
alert("重复密码与登陆密码不相同");
document.sform1.password.focus(); )]rW@l
document.sform1.password1.focus();
return false;h1T*ll.H&gZ6X
}
if (document.sform1.email.value == "")
{ .A rLd G-fH
alert("请输入您的E-MAIL地址"); /T\#Hk$nc
document.sform1.email.focus(); ;V6V0t}GxG D
return false;
}
email=document.sform1.email.value; .m0r9k ^Y y#C&pa
emailerr=0 `lcG:GID p
for (i=0; i<email.length; i++) '~#t,]:l}N Np6_?
{ P!AHWN\6S
if ((email.charAt(i) == "@") & (email.length > 5))
{ Y@j^ o0N"FQo
emailerr=emailerr+1
} /}2f2pF#ln
} V&]Er1U+vW
if (emailerr != 1) 6`e,e K*xKhN
{
alert("请输入正确的E-MAIL地址"); yb{D g'K
document.sform1.email.focus();
return false;
} -C%N(]w-S8@NG(S#W
r&NLQVC;p{\
if (document.sform1.checkask.value=="")
{ DX'or1z
alert("密码提示问题不能为空"); 1vh]%a1b5YS
document.sform1.checkask.focus();
return false;
}
if (document.sform1.checkans.value=="")
{
alert("您的密码提示问题答案不能为空"); o9dmmqf%|
document.sform1.checkans.focus();
return false;
}
return true;
} n P7p+uT.J ef*S2Oz
</script>
页:
[1]