返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
% G$ n5 X) ]/ \1 @4 V* q' l; j<script language="javascript">     - n* {) T! V( V
function IsDigit(cCheck)     
+ \6 l, y/ o" Z% G6 N) L* H {     # d3 G2 b* {2 f9 u4 Q9 p" \
return (('0'<=cCheck) && (cCheck<='9'));     
( M9 L9 B# R5 A8 B- M% J }     0 S0 f& J0 ^4 t
     5 O- p( U, Y. R; W9 f5 ~5 D
function IsAlpha(cCheck)     
  `. |4 C- M% `6 ^6 u0 M {     
2 {$ \1 G/ V2 ?  k- s return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))       H4 O/ K* t' O) R' }4 h
}              
$ V  r* g2 E1 u) ~0 P! T      ' L* b# n/ c' e4 Q) p0 ?
function IsaNull(cCheck)          ; {. M0 G8 A) a% T/ C! k' q, y" k
{          6 `4 @9 N; Y1 g- s. b' G
return(cCheck != " ")         % `9 I: I$ t, @4 o4 ?1 t' c
}                              
3 }3 Y- C  V8 a! U/ [" X      
& z  o! i9 T; j& ^1 ?! w# }function checkform()     4 n4 Y( m# }' H& F& K9 {
{ 6 e/ `( B$ ^/ i/ }% I7 J. |: n
  id = document.sform1.id.value;     
% k. Q1 O" r9 I: W" t if (id == "")     : a( z2 e8 ^% m
  {     0 Y" b. ^- Z" C0 c* M8 j+ |5 ~
  alert("请输入注册名");     
7 S2 |: d8 Q- u7 ]& v  document.sform1.id.focus();     4 O) f0 ?9 ^+ @
  return false;     ' {( r: `' r3 V. ~6 r* k
  }     
6 @9 j% u& H9 C- P     ; I& k3 H- Y6 D2 B: Z% `- _
for (nIndex=0; nIndex<id.length; nIndex++)     
! f2 P, X# f3 K) m) C  {     
- i/ x% K6 {1 ?2 A( W3 t; i  cCheck = id.charAt(nIndex);     ' ]9 @8 S2 a8 ?0 e) M/ @8 }  P! N
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     . A2 Y4 D, e) a0 _1 k0 `7 @
   {     - c1 ~  w) v7 c- m! p% t
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     0 g* `% Y; g- k( s6 r/ y" y4 t8 p5 f
   document.sform1.id.focus();     
/ V8 u* r/ l& M& X9 D% Z   return false;     
3 |# y* ~- x, u6 a* Y   }     6 R; `" R  h. f5 o9 d& L- l8 L
  } - P( N& E, o8 s" b
  chineseid = document.sform1.chineseid.value;     # q( T, ?) B5 t- O7 Z5 r# P" D
if (chineseid == "")     : k. w0 Q  }' z+ C3 J
  {     1 `, e2 s' X% A8 o) p
  alert("请输入中文昵称");     0 }* Q: I. B2 D+ b  ]7 F
  document.sform1.chineseid.focus();     
9 Z' F3 {; d1 N' O9 ]0 {0 @* J! m3 ^  return false;     " Q, G$ W/ g- r. m* N
  }   
9 n' C" {1 ^% M5 b password = document.sform1.password.value;     
' }; ]" }* Y% X# i if (password == "")     
% X  L+ h* [, A& S' Z. k* _  Q  {     5 q+ F6 z  K  _3 s
  alert("请输入登陆密码");     
( d1 l+ M) p: V* `  document.sform1.password.focus();     
$ L8 F) j) o, S( V  return false;     
7 B& o4 X1 a: X5 j; j% A0 s  } * k, y' L& Y* y2 m3 S/ x! j
password1 = document.sform1.password1.value;     
; Z, S! o: `" u if (password>password1)     & M0 ?  m2 H! f+ n. H* ]* L8 ]
  {
- ~( w" k: x9 h) q* \     alert("重复密码与登陆密码不相同");     - O& N5 `, b& J( R- p
  document.sform1.password.focus();
" a: K+ S3 L' C! X( g9 P5 A* _                                document.sform1.password1.focus();     5 {: O: b* V# Y% c% s5 T* B
  return false;" V5 U) Y& x9 E
  }  $ I3 e0 g, D: p0 v8 d  d+ d
if (password<password1)     3 D4 v+ v: E% @8 y6 {
  {
9 |* R, L8 c. a6 s0 l' v     alert("重复密码与登陆密码不相同");     
+ W4 ^5 m3 {; {8 [& l! i  document.sform1.password.focus(); 6 M& V: |8 e5 W1 o2 f5 v2 F/ s0 F
                                document.sform1.password1.focus();     2 I% K4 ?# S' X+ m7 R6 o: L
  return false;  J- H, i3 W/ w8 z4 A& o9 f! W/ Q
  } 5 A4 g% j2 z- K* f+ c
if (document.sform1.email.value == "")     
6 X+ `/ p6 s* ~+ i3 @9 G  {     $ I* s8 [6 Y* c* A# L; n) v9 f% A
  alert("请输入您的E-MAIL地址");     
3 ~7 R+ w' g4 |/ |# R0 b0 R' C. L! M  document.sform1.email.focus();     2 x: M) A: G- X# y  ?8 A9 A: o, G
  return false;     
; C; {. f; Z) e% y- p- \( s9 [6 }  }     
8 q3 u2 v' ^# G+ {7 a4 k7 O      
! c1 Y5 Y, G8 m+ m( \" l) ] email=document.sform1.email.value;      
" w& v7 w2 k2 F6 _# t; f6 n emailerr=0     0 ]) s2 u% h: y
for (i=0; i<email.length; i++)     
+ @' q( d  h1 ]- w4 r+ D  {     , Z8 }9 R" S& U" T$ B& g2 d' c
  if ((email.charAt(i) == "@") & (email.length > 5))     1 [, l3 O1 s6 N: I
   {     - m. U$ Q9 Q0 Q% Y
     emailerr=emailerr+1     
$ R: v" f5 y9 v% s4 C$ [   }     * H0 }4 q4 h. _  y
  }     
  w6 c& R$ ~4 H: g7 y if (emailerr != 1)     
) D# d6 e0 y, q# I  {     
8 K. a9 [/ s- u0 F6 a$ a! `9 }  alert("请输入正确的E-MAIL地址");     # c2 F4 x2 _$ K7 h5 x! g
  document.sform1.email.focus();     . e: V& a( D3 @: `
  return false;     
, p' c3 F# M8 Q% ]  }           2 l  R) K( i% ?( ^( F) `# K
  
* x# @+ M& J5 m" D# l2 Y if (document.sform1.checkask.value=="") ; {& W! R/ `% W1 Z/ ?
  { 2 R0 {! k+ i  f% ~" f" y6 J
   alert("密码提示问题不能为空");     $ i! b& w# S  \4 x; F
   document.sform1.checkask.focus();     5 b8 G+ Q/ V" [( C! p" _
   return false;  
7 e; Q$ f/ D- a0 E0 N, u0 y  }
1 s1 F, k4 v+ S5 ` if (document.sform1.checkans.value=="") * |5 [  S. ]5 E8 A
  {
* G9 d& F% }$ h+ a4 j# w$ y! x   alert("您的密码提示问题答案不能为空");
" z$ O5 x* A0 V, h0 @3 ]   document.sform1.checkans.focus();     
  w/ z1 u5 V9 w$ A7 ^4 T   return false;  
) k- }6 ?' E% c# {4 }! B' o$ J  }, k$ J4 K& P) \
return true;     6 a/ I3 q+ r8 ^3 `3 y+ v
     
/ r; ]1 q# w  u$ q}
& i% Y) Q! N0 B( k</script>

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