返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
7 B# g' F  x6 l  @: o# E<script language="javascript">     
! }) x) o3 g4 Jfunction IsDigit(cCheck)     
* D( @( h* f7 O" H" w  u {     & [  t$ B. U4 x0 \' Z. ~
return (('0'<=cCheck) && (cCheck<='9'));     5 x: x" P7 U' l) D
}     . L1 R; g& E. t( a3 b
     
6 N" k% E! r* `1 O. p& Y! @9 ?function IsAlpha(cCheck)     
, ?4 w. q5 \) ^' T: r {     3 p& }3 \2 Z" M+ P, w# |
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
; p3 c0 g- {/ `/ c* c3 ^ }              
1 C. t1 E7 ]8 E% E" @* z+ J, H# f      
6 M& o" j: q5 E+ Jfunction IsaNull(cCheck)          1 N) C7 m4 |8 J- X$ n% P8 x: V
{          9 r0 v* a, M" g2 c; {- o& n0 f8 O0 W' V
return(cCheck != " ")         1 w7 h1 |3 L0 P9 j) B7 C) s
}                              
3 V% f" H( {8 O      
( Q  A+ q: A- p" G8 P- r3 V* b0 Bfunction checkform()     * p# n  r* u+ Z2 {" i: _, D
{ ' a. U& D8 P( D
  id = document.sform1.id.value;     
6 R8 u% @* ~$ H6 G3 p$ U if (id == "")     & _, v. R/ D. u. f2 ~" d1 E# Z
  {     
, h9 ^! `* ~) M; [3 @# a7 U  alert("请输入注册名");     % }3 {) F9 H1 y" C
  document.sform1.id.focus();     . V8 u: N; n6 w, ?, G2 U
  return false;     5 _* W. z% D7 b5 p
  }     $ d7 f) S  G( `6 L2 I6 Z' S
     ( y+ Q; j7 [& \# L! F* ]
for (nIndex=0; nIndex<id.length; nIndex++)     
) t# W5 V) ^/ X, z1 v! K" m: r9 x  {     4 L& w# e$ W% s" K) e3 n
  cCheck = id.charAt(nIndex);     # O) K. }( r1 e" ]+ Q' y( S% a+ U
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     $ T. F# X& \% u  U4 t* d
   {     
( Q4 l7 M+ w3 {, z8 x$ d   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ) l6 D& Q  k6 o, I3 F7 Q3 x
   document.sform1.id.focus();     
$ t1 [* |" D5 P$ w, U   return false;     
3 h$ V3 b/ U3 Z+ J0 C) k- O$ s   }     5 j' \3 d3 A8 l$ U. [0 ]  {
  } & K$ E1 b+ u+ h. r+ A. S
  chineseid = document.sform1.chineseid.value;     
+ Y) h8 W( e$ W& j% D3 ~ if (chineseid == "")     / a1 E6 R3 Y5 ]$ J
  {     . _: j; V  \- c1 _) L4 F& f5 x: n0 d
  alert("请输入中文昵称");     " i+ e" X) }& D. a
  document.sform1.chineseid.focus();     
) X/ H8 v4 H& c3 X0 h  return false;     
" J/ Y5 ~/ k! J$ J/ b3 H  }    0 r. `- L6 d7 A  D4 C$ X
password = document.sform1.password.value;     9 U$ _' B9 y; q5 U7 A
if (password == "")     
; c8 k9 S+ O0 c1 \/ _  {     
% a: o4 x% t6 J" ?. c" A  alert("请输入登陆密码");     
" O) t4 F5 e3 w3 A1 k6 E  document.sform1.password.focus();     ) t- O: x" l, n
  return false;     
# o+ B5 A  y' w' C$ y6 t  }
0 K" v& }. b9 \$ q& _/ i password1 = document.sform1.password1.value;     / C7 W" c2 S3 n; h2 r0 A/ q* t
if (password>password1)     / v0 w2 D" @8 t
  {4 q5 f9 N4 M3 _( G) v* h" l# p
     alert("重复密码与登陆密码不相同");     4 Y6 K4 z1 R6 ]2 E) u$ O7 v% r
  document.sform1.password.focus();
& l" D9 z8 g9 f2 O9 W9 Y; W! b                                document.sform1.password1.focus();     * D4 U3 W9 b% p% P# G
  return false;1 Q9 P) l# b1 E1 |8 ^% M
  }  ' L# Z, S2 C2 P# p; I& a0 v% |
if (password<password1)     $ m  v% V/ z& A* P1 g. `1 `
  {
6 C" g  Y; h6 R     alert("重复密码与登陆密码不相同");     9 r9 |2 ?3 {4 j. }+ Y) I
  document.sform1.password.focus();
1 \& W8 p, H# u2 b  F" @0 Q5 I                                document.sform1.password1.focus();     ( A, Q5 P$ a7 |
  return false;5 l1 I4 c  L$ }: Z5 g5 A' p7 t# S
  }
. s2 r, z1 ~+ ^5 c+ C" T, j if (document.sform1.email.value == "")     
7 t# g( e* b. L  @  {     
/ K' x2 W4 t7 U4 X  alert("请输入您的E-MAIL地址");     4 x1 o4 I; q6 b! O* `6 Z
  document.sform1.email.focus();     
% k) Y2 i0 [' e7 P% x( T' A5 _. t  return false;     
5 f4 K' t# u3 S: W  }     9 q4 X# N$ h7 i3 B& I2 G  g
      , M* j! L$ I' M$ b- j
email=document.sform1.email.value;      ; J  \# h4 L- ?) |2 _* H; c
emailerr=0     - O2 s7 \$ p5 ?5 t# W# m
for (i=0; i<email.length; i++)     
/ K0 G3 H' d7 k  {     
3 p; F8 H# G0 z6 E, B, Y3 D  if ((email.charAt(i) == "@") & (email.length > 5))     0 s1 j4 h& e. H; ]- g: l
   {     
6 X- r2 W5 [4 o# p: W3 E" g0 n     emailerr=emailerr+1     6 g( C7 [: o; P) h& S3 e3 g
   }     
: p, q! I2 T  n  c  }     3 d) q1 ?# \% o* @
if (emailerr != 1)     2 W5 y! G; j) N" P4 H& J8 }
  {     
0 c' i1 r7 @' [3 D  alert("请输入正确的E-MAIL地址");     ! ]2 }( `4 T0 ^9 M1 ]! t# _
  document.sform1.email.focus();     4 `7 S" e8 ?0 d: O
  return false;     
) E: O! S; t7 ]  }           
$ _7 n8 B2 d; T% ^7 |  
# L0 A3 P8 L" O" X4 ~- q if (document.sform1.checkask.value=="") 1 i1 x$ X+ i3 q! ~
  { # W4 T( Q; c/ p3 g. u# Q
   alert("密码提示问题不能为空");     
# O. n6 T% e7 Z) [7 X0 `9 q7 A& u   document.sform1.checkask.focus();     , F) C+ Q" P8 t6 f4 [$ e8 ]  {
   return false;  & i8 w* i9 `8 q4 i4 r
  } . X9 {3 m9 Z2 {0 p
if (document.sform1.checkans.value=="")
5 t% U2 ^, l: Z6 T/ i  {
* T6 d" C% N3 ~: _$ ?   alert("您的密码提示问题答案不能为空");
2 ~; X8 p# T/ M) W2 t4 v   document.sform1.checkans.focus();     
) Y& a( u2 ~4 q2 E" n   return false;  
2 ~# r$ e) b+ ?4 j7 x  }3 G$ @0 t- g6 E1 w; n% O; A
return true;     
8 [4 L/ f% ?% ^: J- w* q! Y9 n     % u' H. Y0 u( w, J: m
} ; e( \0 }& f! Q' X% R" w$ ^4 b
</script>

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