返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
& V3 ?$ {. m  Z! ]<script language="javascript">     
  C" y! u( s, A: w* Pfunction IsDigit(cCheck)     
2 t) e& L2 I) [4 ~# u5 c {     5 d0 ?0 R6 T! |4 j
return (('0'<=cCheck) && (cCheck<='9'));     + q9 }+ X, y; B1 R0 e
}     
) `: ~% _7 F% o# t9 U. Z0 q     
4 H6 z" ]6 N5 t; ~1 `) @% dfunction IsAlpha(cCheck)     
0 z4 O6 c) n" t, a/ ~. k {     - T' t! S" k8 }6 g" \/ g# q
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
; b, a7 I% ?# L0 T+ W4 A5 M }              
4 y9 o1 W. ^6 g! `9 B' P) ^* f% ]      - O% Z! S- V( s5 u
function IsaNull(cCheck)         
1 ]  G* Y5 c. h5 T' \- N% P6 g {         
) s8 G- N( y. K+ R8 d' D& M return(cCheck != " ")         . U- N; s1 _/ d
}                              
( R$ z3 o- p/ r7 p, a      8 H1 m" E  W! n. M: O
function checkform()     
: ^+ A' w) o. ^! m{   P! l$ d! E! M- Z
  id = document.sform1.id.value;     
/ C. S6 T7 G' w1 { if (id == "")     + u( T4 V" C2 o8 ^9 t
  {     
2 [6 c$ h( \' C. S* E4 }  alert("请输入注册名");     
& {) C6 d$ r; A3 m; q2 i% K  document.sform1.id.focus();     
+ u( Q7 v! P2 Q9 k( }; y: h  return false;     
* ^3 k  E' V4 G7 O8 I5 C, K, g  }     , |* h1 a6 i. E
     
' Z# _1 s# w) S, B& q for (nIndex=0; nIndex<id.length; nIndex++)     
% p8 S/ A( u" A  {     ) n! R$ c4 \  M
  cCheck = id.charAt(nIndex);     ! z; N$ n9 e1 o$ l. O* g
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
  H* ?  C' y- g  m# V/ M! j   {     9 i! d5 M" |) t! E7 T! [6 `
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
* a4 y; g, X# g0 o. t   document.sform1.id.focus();     
7 K" l$ @4 Z; v7 D7 C# }! g   return false;     
6 x7 g; |( `0 z6 f4 d7 `   }     ' S& N6 O* W6 ]: ^9 q
  }
7 a; h( C1 q: U/ b% z% r$ |, G  chineseid = document.sform1.chineseid.value;     
; @' D" ~' ^; C) ]  S1 N4 @ if (chineseid == "")     
. `8 }" {0 x8 c  {     
) u9 k7 p1 c: r  alert("请输入中文昵称");     
9 D5 l9 j9 m+ f$ h4 X7 B) Z  document.sform1.chineseid.focus();     
% D2 Q0 B( |, H& {0 |0 r9 M0 m  return false;     1 Y3 E% d2 E! h: k+ s0 E( c
  }   
* s; X$ ?" q% @9 z% i* ]! Y$ E' J5 k password = document.sform1.password.value;     & A3 H$ B. {* q/ U/ B0 _5 W7 z
if (password == "")     
: ?2 \1 ]6 P* n/ O5 |6 O  {     
* q" S9 ]9 R* E9 r' M  alert("请输入登陆密码");     $ M& S4 y, z+ r8 K% |
  document.sform1.password.focus();     
! @9 w9 q5 S% m1 L& l) [  return false;     
3 o  J, O: v  G# a/ c5 W4 |7 s  }
6 Z* w  D8 R1 n2 H password1 = document.sform1.password1.value;     
% T9 {2 F& Z& u5 P7 Q2 C if (password>password1)     : e! H* ~% y; _" Z) M9 |
  {
$ X/ F) ~$ s0 I: I- f     alert("重复密码与登陆密码不相同");     3 N1 n; {$ ]) t
  document.sform1.password.focus(); $ Z; X. {/ s) J! i
                                document.sform1.password1.focus();     2 j. t' L0 n. e7 k
  return false;( c) R/ e. x8 S' `# T' q
  }  9 R* U/ c1 W7 J7 P! h; ~
if (password<password1)     
0 c% O  q! g2 G( Y  {
9 [' Q0 l) `: d     alert("重复密码与登陆密码不相同");     
- s0 ^" t) X" O6 Q" r  document.sform1.password.focus();
/ X9 O* {4 ~9 g- e4 Y1 x5 Z                                document.sform1.password1.focus();     
6 h3 D( Z. P" n& y9 k6 }3 G  x9 b  return false;
1 Y$ ]" t3 O3 c1 l5 U  } 0 j6 Z. u. E9 A+ Q; A5 A
if (document.sform1.email.value == "")     
/ H) e* j: F, Q' `. A. V: B  {     
; F' V8 Z. Y4 y$ l+ t! x* j; h  alert("请输入您的E-MAIL地址");     ! @4 L1 r2 Y: ^) @; ^  l) J
  document.sform1.email.focus();     
( v3 {2 Q' c7 j: E& U  return false;     + m# b7 {& p2 H# P) Q
  }     1 p: |3 h  Q9 z6 X" N  b3 p# H
      ( U: z7 y& s* v
email=document.sform1.email.value;      
4 H$ L6 i4 u/ s  s# x  ?3 L5 E emailerr=0     " |; C& Z) m& k/ |
for (i=0; i<email.length; i++)     
) g  i; P1 W: d/ @) B8 ]2 ?) Q  {     
$ {4 D* a- R! r8 i# B  if ((email.charAt(i) == "@") & (email.length > 5))     
% l+ \0 E3 s0 F/ }' Z5 u( Z& j5 p: k   {     6 q% Y  S' g! l
     emailerr=emailerr+1     6 E5 T, d/ I4 Z7 J1 T2 K
   }     
* `! E3 L5 c7 s. G# J  }     1 k) ]4 S' U# o/ u% ]1 F
if (emailerr != 1)     
7 t% Q. \6 X; |' u  Y$ G  {     
- s. x& s  h4 ?: M  alert("请输入正确的E-MAIL地址");     # a; i' U" c4 ]- [2 y
  document.sform1.email.focus();     1 b3 n! t3 K& X$ S+ ^
  return false;     5 c, G2 ^- c6 x% ]
  }           ' W" O1 |& C; j! J' N' s" |
  # j  S2 x; c% Q
if (document.sform1.checkask.value=="") " N5 g% f7 ^% d2 H5 ]* P0 [% Z: g. U
  {
1 K' l* J$ k8 P4 L6 Y9 Y' i   alert("密码提示问题不能为空");     
, {  e: y% |! A   document.sform1.checkask.focus();     
2 ^3 r8 J2 ^7 V5 U% ~) |; P  [* K   return false;  ) Z- U' i; w# y
  } * O: ]% @* Z  f/ s4 v* v
if (document.sform1.checkans.value=="") ! H( W+ ~: D" |) _" l
  {
% n+ c* c9 \6 r* U3 A- E   alert("您的密码提示问题答案不能为空");
; f* q4 v1 O6 z! c; k( M   document.sform1.checkans.focus();     
  o5 W, k1 J4 A4 y3 E2 |9 `' _5 v, w   return false;  
) |" c, L5 w( o  }  N& }7 v* y+ J& j( d; k" a
return true;     0 `- o, W" f' Y1 f- h
     ( W8 _7 j! }& }
}
- W% F1 J+ _6 K; @: Y</script>

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