获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
' h5 P5 U  L- T3 ?9 h2 d5 t<script language="javascript">     
6 {0 b; ~/ d) {7 b/ u% Wfunction IsDigit(cCheck)     6 A9 d9 P& E7 T' E
{     
2 z' j# g0 c3 F' H return (('0'<=cCheck) && (cCheck<='9'));     
$ Z. n7 p" |* C( a: l1 i! T, A }     # K; e1 j6 Y. H
     " P8 \# E( e; \; t4 E2 Z0 z7 _
function IsAlpha(cCheck)     . N1 ^+ ]( |3 e5 [
{     
6 R1 U; I3 _; q4 `  E  N( J* H return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))       D! ~) q, A+ g- E, C; k7 P5 F" Y
}              : v( H6 u7 D9 L0 G  _/ b; x# g
      : ~& Q! ]( F/ `5 D: C* ?3 L/ ?& g
function IsaNull(cCheck)         
& B' L4 Z6 R3 [5 b, `8 G1 Q {         
- t9 S% _6 y& K! Y$ }+ ^8 B return(cCheck != " ")         / l( H, K5 O+ P" j
}                               8 G2 |9 V0 ~7 f0 x: i
      ) o: Y1 m) d+ J$ F: A/ H
function checkform()     9 Q8 C3 n7 L8 U3 y5 P9 U4 n
{ 7 m, M( `( t0 S, {3 ]
  id = document.sform1.id.value;     / S. Z! x8 ^& n8 ?; O: k( W, j
if (id == "")     
2 x! U, @, d# w' v( K  {     
0 v/ _8 t# ]( N& x: j2 g  alert("请输入注册名");     
& K& p% t/ f* y% V. p& Q. w4 U  document.sform1.id.focus();     
, R9 g- \5 B+ g# S8 K# S  return false;     3 L# C' U' R0 ^) X" C5 T  i
  }     5 J: [* p. Q9 ?+ f. W
     % _7 ]7 @/ d7 S& K# o( d
for (nIndex=0; nIndex<id.length; nIndex++)     $ b4 Y% \. T* d$ K# ?+ N. d& _
  {     
! B3 L# y! y8 }9 D* b$ c9 N  cCheck = id.charAt(nIndex);     
# P, _1 }" m% \' n: }" t# x  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
, x4 b% Z9 V6 q! H6 g" y   {     " M# d5 c' R" e& _
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
9 K7 x4 J5 u9 y, d+ R% i5 L! |   document.sform1.id.focus();     ; A: u( W/ q( X! Y" X( L
   return false;     
: J0 a2 j/ b- K2 m! c$ {  n   }     ) O  i; D; p: [0 T
  } ; ?# O3 j  R+ u6 P% v" O; X
  chineseid = document.sform1.chineseid.value;     ! {. y; C( C2 H  G! ?" l+ t4 y( p
if (chineseid == "")     9 ?, u! k/ I+ a" K- h: ], |. V
  {     
. O! y# b) p8 |  alert("请输入中文昵称");     
2 |& K* i  L0 y8 O. Q  A& L  document.sform1.chineseid.focus();     & ]; `+ c$ g8 R
  return false;     
- V! U* s+ s: Z  p3 f3 }  }   
7 i$ I/ K$ Y2 U password = document.sform1.password.value;     
7 M/ G. [& S% E if (password == "")     - I4 c* L. R& l( n3 }5 \4 K
  {     4 \) K3 o; f3 N! b7 ^3 y
  alert("请输入登陆密码");     ; y# M1 N( G. T1 ~- t" r
  document.sform1.password.focus();     0 K0 E5 {5 Y$ F$ g. v5 t
  return false;     
3 e# o7 }* k: M* m1 l3 |" R8 [  } : g8 S* G/ |1 E3 p
password1 = document.sform1.password1.value;     . u! f* @1 p3 G5 v
if (password>password1)     3 T1 f4 Z' o! s
  {
$ G. q3 m* V# t4 w     alert("重复密码与登陆密码不相同");     
* u. _# P* h) `8 h& {1 e6 [4 C! J  document.sform1.password.focus(); 6 v$ e7 S# V# Y7 A# ~' U) S. |2 p
                                document.sform1.password1.focus();     
3 X. s) r4 n6 M5 U6 U9 u3 J  return false;
; x) x/ o5 r3 b8 w" b  }  
2 j1 t5 M( s5 |if (password<password1)     
4 g; v( s( Z3 ]  {
' E/ s  b8 Y" v" ^     alert("重复密码与登陆密码不相同");     ) L/ n* ?( g' r* V& t( {
  document.sform1.password.focus();
$ O* b. ~  c, `2 P0 U* L                                document.sform1.password1.focus();     
5 N8 C$ m7 g& m1 Q! {$ N/ o  return false;- i9 h5 s8 C* e
  } - V7 J2 z# u4 X+ e7 ]9 D
if (document.sform1.email.value == "")     ! T, c" k& y; m$ Q
  {     
5 x; w. t4 [( u% C6 \  alert("请输入您的E-MAIL地址");     
+ b+ G0 Y/ o7 B- v( p2 x/ v: O  document.sform1.email.focus();     
. s1 _! S# Q- B/ V! a% j; h  return false;     
; O5 a8 n9 M. I0 x8 r7 S$ W  }     + T/ ^# w' e1 G! \
      3 _9 v' U+ j5 E% |# \, c
email=document.sform1.email.value;      
- b* \+ ~- R, @2 H: t) T emailerr=0     : I* _8 F7 G6 W
for (i=0; i<email.length; i++)     
4 f* A- v' S4 R5 s8 M  {     " I$ T- E8 W8 ^: J
  if ((email.charAt(i) == "@") & (email.length > 5))     8 S; I& p5 Y4 b" `7 T# b# A
   {     2 w# V5 `( x1 m% o" r! \1 U% P7 _
     emailerr=emailerr+1     9 {8 n/ }  A1 O4 C
   }     3 z, J8 n, N+ k0 b! ?
  }     : q% `# l: C+ a, n; l
if (emailerr != 1)     
2 {, n# e. z% B, r  `4 K, \  {     
/ d. X! M0 N+ G  }" K! v  alert("请输入正确的E-MAIL地址");     1 u+ a" k) k6 o  M
  document.sform1.email.focus();     
3 {, \; G2 L% _5 |* ]" K  return false;     6 ^9 U0 d8 s) f+ H
  }           - p5 ?# Z+ z$ w
  3 I! W2 T1 v& B2 @# Y
if (document.sform1.checkask.value=="")
4 s" e( n* E$ ^" U/ w  { 9 x8 u8 |/ c1 k1 U4 T' v7 G, m& |
   alert("密码提示问题不能为空");     ' P5 J0 ~/ O1 s# z1 ^
   document.sform1.checkask.focus();     
0 j3 g% u' [6 n* h   return false;  
3 Z3 C: p0 u. j  }
+ o2 O* _) N5 E5 r8 W+ d& M9 l if (document.sform1.checkans.value=="") 5 }. L0 A8 E: _4 M  {! a3 L
  { 3 `1 n0 }1 ], N, M. S
   alert("您的密码提示问题答案不能为空"); 1 c' ]6 c5 ]9 W
   document.sform1.checkans.focus();     . F# Q* Q. [7 _: |1 ?
   return false;  ) L5 G: w% b: o! l; O
  }& M  F! y7 J: m4 L
return true;     * B& G& o4 V6 [2 A8 g
     
4 t) j' ]6 u) M6 b}
4 i  U% C( `7 M- P9 G</script>

返回列表
【捌玖网络】已经运行: