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

一个注册表单验证的js

这个脚本对你可能有帮助:
! e  l" @9 p1 y+ |0 O6 n; l<script language="javascript">     
  x3 _! F9 `+ h; Z4 h4 zfunction IsDigit(cCheck)     
" h! R) X+ H: o4 g; u0 N {     
4 R4 e4 e7 Y5 v( e4 x7 x return (('0'<=cCheck) && (cCheck<='9'));     
; N1 I, M( ^( R  F7 \ }     6 l( E: Y1 v# A) P6 z
     - A) }# V: _" ]: N) {5 j
function IsAlpha(cCheck)     
9 r; T, n# Q+ `' u {     
. C+ C' u/ K4 {+ r. ]+ @+ |) W return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     * }8 K5 R  t4 c7 z6 k; ^$ K
}              4 V8 e2 h, |3 F7 A  r. O
      # e+ s3 y, i" E: e, [- X' c
function IsaNull(cCheck)         
( E) N5 b* Q- y/ D {          , P! v6 \* l" H
return(cCheck != " ")         9 U2 j) `( u0 i
}                               8 b) A4 |7 U, \4 _
      
" b1 g) ?# m8 e& F2 y! w3 k% Zfunction checkform()     
- Z9 r7 Y0 }3 q' H- {7 ~( y{ 3 D  n- H5 }! c
  id = document.sform1.id.value;     ! P. B' e3 ]' w" \, j8 ^/ I
if (id == "")     $ y8 ^% e' x1 |2 f7 W
  {     
9 {' Y( e0 ~& w4 s& K) b1 ?/ e  alert("请输入注册名");     # j* ?3 B8 R% V& `
  document.sform1.id.focus();     9 l7 l# ?- I' s+ a+ [& ?  @5 @
  return false;     0 [8 x  ~. z& u( g7 H: G4 V1 \
  }       i# p% [. i  g5 T) N5 S4 Q  T
     
- c' d, d8 q. W for (nIndex=0; nIndex<id.length; nIndex++)     3 }/ f4 d; @6 S" }
  {     : N$ ]  C% y+ H* H1 r- R
  cCheck = id.charAt(nIndex);     ; Y: C' S) p/ Y1 C# o
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     * n: _8 v6 U: f9 P* r
   {     
7 c0 K8 x7 w5 N   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     / _+ l+ }0 l6 ^
   document.sform1.id.focus();     
/ V, ?& L) M6 `" R" w   return false;     ! Y$ W1 K- N) y0 S! |+ t
   }     
( K* ?; C9 V/ n. c5 x  }
& H3 B6 C& i5 ?" i7 m$ t; f) G. U  chineseid = document.sform1.chineseid.value;     & v& }! k( i5 \  o3 x# u
if (chineseid == "")     
. m- N: u' E: a- f* N  I  {     
, v/ I8 f8 A- v7 Q9 x9 e; V; _; r' u2 V% O  alert("请输入中文昵称");     % ]& D, V9 E& W7 b) g4 h
  document.sform1.chineseid.focus();     % L8 x# ~; ?+ |# O7 W( b) h
  return false;     
+ ]; T. Y6 e2 p/ W& i4 l2 G4 ?) U: k  }    4 |! C! B0 c2 @8 o
password = document.sform1.password.value;       [6 s9 t8 _% B+ H* A6 a0 \' L
if (password == "")     
6 P! R7 Y& \% ]; U! f4 o! a3 L  {     
: e" D. I) z% m0 k) p  alert("请输入登陆密码");     * K$ i  z' a( c6 t. @; W) P3 @8 t
  document.sform1.password.focus();     : d- t. {1 n% f- o9 Y" m" q8 n
  return false;     : _' t! y# J. Z" U' p
  } 3 i; b9 l% z. @+ f
password1 = document.sform1.password1.value;     - e" T9 A/ {6 U5 r2 ]( n/ R
if (password>password1)     
% c) e5 G* u3 |7 N6 [6 ~- M  {) q. P) ~) E+ k( Y7 [% \4 `! G2 Y
     alert("重复密码与登陆密码不相同");     % a/ v1 u7 J0 v$ j0 J
  document.sform1.password.focus(); ' k5 r; s' C& O1 A4 Q- }
                                document.sform1.password1.focus();     1 `. r1 [: E7 O+ Z% f
  return false;  M" f7 l. [' J9 H* f" T
  }    l; j9 Y% U6 ~; j
if (password<password1)     
1 I3 I; u$ e+ R) i& P4 K  {1 W' I: I% d6 w- t# ]4 V! B
     alert("重复密码与登陆密码不相同");     ( j" d3 u1 {% T8 g! w3 F0 R" }' M
  document.sform1.password.focus();
( ]% m- @/ x9 o( G" M( n4 p                                document.sform1.password1.focus();     
* O. r5 a' M. x1 b2 ]8 s6 b( Z  return false;
0 c# E9 O6 e  v: b$ M. X  } : \1 s0 W; o) B& H4 e- ]8 z; P: W* G" x
if (document.sform1.email.value == "")     
; P8 ^* h. y8 l7 x3 |  {     
% i. v) [4 s! Z) W2 ?) X  alert("请输入您的E-MAIL地址");     
" P2 Z/ I; C9 A" ~, i+ W2 G2 _) ]  document.sform1.email.focus();     9 o5 F' W, V) i; h# n
  return false;     
- ~6 {1 x& ~( C/ g1 k  }     ) Y' w, p5 V5 Y% f% d  C( C7 A
      
3 V% A% W/ M# E' p email=document.sform1.email.value;      7 A/ }1 F( Z+ q" \
emailerr=0     
8 ?4 {7 j2 a. r# s/ ? for (i=0; i<email.length; i++)     
& {( s1 ?& g5 x; R+ y6 L  {     $ G* w9 v3 \, ~7 i0 B. n" v: {
  if ((email.charAt(i) == "@") & (email.length > 5))     0 S! D5 J$ v' a1 k/ B+ x/ p: A) Y
   {     
  O! t7 X$ }" l( T     emailerr=emailerr+1     
: q/ E. U0 c" g3 q   }     
* l! a! A- Z& H  }     
* \& m+ ]3 g5 o& B2 T- R if (emailerr != 1)     
4 a# |9 x( k& p# R% e- _7 g  {     " t/ w" C/ W3 `* m; ^7 b! h8 h
  alert("请输入正确的E-MAIL地址");     ! D" ]! t0 e$ u. g, x3 D
  document.sform1.email.focus();     
6 J8 _; F! T2 `) d  return false;     ' [/ h9 {& ?& _# Q
  }           ' d3 h7 l7 z/ e
  3 j1 |) p3 S' \  J
if (document.sform1.checkask.value=="") & ^, c+ H: [- Q6 Q2 r
  { 1 B# }2 f3 T& y5 g" ]5 e; }4 p' G
   alert("密码提示问题不能为空");     % g. H5 w5 T( V1 j  P+ h
   document.sform1.checkask.focus();     ; G. m4 a* ?1 C! v
   return false;  & @8 t, f4 P6 k$ I
  }
: S0 I5 B! q& `9 l: X if (document.sform1.checkans.value=="")
2 o9 n+ L# y( H! }$ l' Q5 O  {
( u  T, k0 S' F! Y- g5 \   alert("您的密码提示问题答案不能为空");
& C% V* d1 l& f5 D   document.sform1.checkans.focus();     * W7 P1 q1 h- g' }+ _$ c
   return false;    J  D6 d! a' `. v% t5 V2 b
  }. Y1 M. z- u/ E3 F; O$ Q7 K
return true;     
# Z: [+ E8 R  M( C: j3 y- r) G     7 G; ?0 ]+ A: _& C$ e4 w: A, |
}
7 O' P1 I9 r- h7 F</script>

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