返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
+ l2 _3 \% r5 c% f" H, k4 M: g<script language="javascript">     
9 H( i$ q# ~/ p. I, f% X- }' Sfunction IsDigit(cCheck)     
$ j3 N, d1 C; M- z' t$ i+ \0 p9 x& S' p {     
* h6 M% u! _) P6 c return (('0'<=cCheck) && (cCheck<='9'));     5 J( X; M# f. ^  s
}     0 D$ v  ^+ T7 j( u! G! ~8 A
     $ v4 D$ R9 e9 d; }- @
function IsAlpha(cCheck)     
7 [! D8 x" k9 E* o. ^ {     
% c. s( u$ o2 z/ Q' X+ q return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
" Y3 }' K* ~9 D6 }9 ?8 y3 t }              
9 D; K7 s) \" x3 ?" H- _      
, S# X4 S  R  Q" I+ _4 O+ O) Q0 h6 ~function IsaNull(cCheck)          8 [8 I% k8 @7 f. T: Y
{         
. E7 g& t3 o' H" W6 y4 m/ _2 J* | return(cCheck != " ")         
; s; i- W3 r- a# [* ` }                               0 j; x9 }3 W9 \( |, u
      
/ s# ?8 P. _0 T* I9 e' Efunction checkform()     
( V/ Q6 V4 M/ n: s{ 5 Y) \  @, a% V. m. W+ f% c
  id = document.sform1.id.value;     
# ^+ r! N& h; `7 K2 y& ?* i4 K if (id == "")     + M( v3 @7 D; @( t% Y& c
  {     
2 f- A/ ?3 ^# [/ t- U( x! F  alert("请输入注册名");     5 Q7 q+ C0 K6 h& @4 j% a
  document.sform1.id.focus();     ) f9 N0 V; u) v
  return false;     
* h) \: z3 T6 V- y: m2 s$ q  }     
9 o5 I- B( _0 z9 j! |1 i     
0 ^- j7 H" P8 b for (nIndex=0; nIndex<id.length; nIndex++)     
; b: o2 m& u9 M+ r/ p  {     3 y6 m9 B6 b+ y  z& i$ w3 {- f
  cCheck = id.charAt(nIndex);     
; [: K/ |9 y) k2 n: D% }7 K6 g  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     . N# O4 D( ]) J' }9 |* v6 C
   {     
7 g7 Q! U' u0 B9 B% G. I+ ~$ c/ E   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     1 u1 X( x( ~+ E/ y9 _$ g9 v
   document.sform1.id.focus();     * [# R& p- r( M3 S( O7 P
   return false;     : I1 _8 h2 X4 C3 {1 L6 q9 f
   }     # c$ U% p* C6 _, r  E1 X+ j
  } 3 M6 {% F2 Y/ R
  chineseid = document.sform1.chineseid.value;     8 ~% l6 J' z/ ]" S. ^# s" Y
if (chineseid == "")       F* Z7 p; |4 V, j% m. ]. o/ L/ v5 N
  {     $ H2 I! R# Y6 Y3 W2 \
  alert("请输入中文昵称");     
! k% O3 s+ |. O6 f4 t2 i  document.sform1.chineseid.focus();     # `! W( R, E" i5 T* }$ v/ x7 E
  return false;     $ F8 l% v- m: k. n7 J" x* `" a
  }    % y0 M5 d1 a7 E7 N- Z9 p
password = document.sform1.password.value;     " q" h3 f; Q& I
if (password == "")     
( X+ w7 L' ~5 E" n  {     6 Q, e  b2 C( {
  alert("请输入登陆密码");     
% `! {( N2 q* M/ P% W, x) O& N  document.sform1.password.focus();     
$ _+ Q5 M- ?" }! b1 E5 T  return false;     6 U# y- z: E& J8 o
  }
# Y) N5 `) e8 N: F. l. ~+ b+ @ password1 = document.sform1.password1.value;     % t4 L( Z; A+ G1 }& L
if (password>password1)     
  D$ g5 i4 J. G/ V; ~  {
9 v$ I& r/ @7 x1 v: S9 ]- P     alert("重复密码与登陆密码不相同");     ) J% Y/ v0 z$ p3 V8 @1 W
  document.sform1.password.focus(); # ?( E! j! s5 W& `2 U
                                document.sform1.password1.focus();     + A# f8 O2 C, w9 g2 Q4 O, u
  return false;
" q3 l7 E2 ]7 g' A1 Y5 n  }  ' b! w; b( t; ^1 N- ?: X
if (password<password1)     
/ E1 V4 b. B1 |/ d  {" G0 o$ t4 r' s# f3 y( K
     alert("重复密码与登陆密码不相同");     
' i+ K# ~, C8 P6 N& e. a  document.sform1.password.focus();
% Y( J* t/ d# h5 E: B9 A. o- `                                document.sform1.password1.focus();     & [/ Z) H" ^9 w
  return false;0 }) N' g5 c$ f+ o% h7 L# B& m$ v
  }
+ C4 E" L, E# x) k. { if (document.sform1.email.value == "")     * z1 U' {* l  M, X
  {     
3 m8 ~, i' D: f& j9 T  alert("请输入您的E-MAIL地址");     
& W( {, @; U+ t+ e  document.sform1.email.focus();     2 C$ B& `2 l7 z1 i
  return false;     2 M  R' k2 b8 ?  [7 |+ F
  }       ]$ w- c" ~8 s" t
      
' p( A0 @7 t# b, e( j4 d) b email=document.sform1.email.value;      & {  t: S; y" Q( ?
emailerr=0     3 ~" `( D7 A7 u8 H$ ?5 b2 D6 I! t* g( x
for (i=0; i<email.length; i++)     
6 H. L% Y+ `+ f9 p' q0 f  {     
. w% w' |# s. R" r  if ((email.charAt(i) == "@") & (email.length > 5))     
% Y9 v9 b6 G' R: Z; \   {     
/ L) d8 U1 _0 @: @1 P6 l     emailerr=emailerr+1     
0 [0 k# Q$ F+ O   }     
) y9 b; |- [7 p' ]  a# y  }     
3 m! x4 G" |- @! Q- J5 ~" S if (emailerr != 1)     & _0 Y. x& ^/ e% t: m" x6 _& l* W( n
  {     
# }" S- C: @* M5 G  alert("请输入正确的E-MAIL地址");     
$ c& k- `+ h) Y# I  document.sform1.email.focus();     
8 J. f% ?: c1 l  return false;     
+ b7 ^: F* W/ i% {  }           
- }8 ^) I  b( y# f  ) t9 O* e3 y" S; r
if (document.sform1.checkask.value=="") % y7 s4 R+ d& b& L/ k
  {
7 }' Q6 H1 V/ n3 c: k   alert("密码提示问题不能为空");     ( H; i" q' G; v" f2 \1 n6 l, U
   document.sform1.checkask.focus();     3 \$ I' Y* g8 Q" {- i  M  p
   return false;  ) x  ]- j* d7 G* e& \# G
  }
1 `2 O6 x1 h: b# i+ Z* t if (document.sform1.checkans.value=="") , o5 i+ `1 {! m
  { ' S) ], Q9 n! c7 o
   alert("您的密码提示问题答案不能为空"); ' C1 ?# G) E% n+ s. p
   document.sform1.checkans.focus();     4 D! c* C) w. `( }8 N6 L
   return false;  
. u8 {8 Q. Y7 D0 d$ ]2 O" B  }3 b5 r7 _' `( v8 B4 ]) A( [- d% ~: O
return true;     ( z- R! q  x  a
     
/ F/ X  y6 a, `$ |} ) a) I1 h  Y) J* Y6 t& f6 @
</script>

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