返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
# R/ d3 j/ R+ i2 j" K# f<script language="javascript">     
( h- D- w/ r! V+ q/ efunction IsDigit(cCheck)     
2 u5 }4 `6 \. W2 f- q {     5 P8 D: d% f, Q) U% w+ p9 f
return (('0'<=cCheck) && (cCheck<='9'));     
/ P. Q2 p  Z. Q- _( p( G5 L }     
- h- p  F2 v% s2 q6 M     
2 g& q* [1 I5 p7 ?0 Bfunction IsAlpha(cCheck)     
; W) _' q! |7 t$ c1 |, x+ h {     
: m- D% K' c) {' ^/ H2 [ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
& ]2 S6 a7 e5 x0 `3 `: g }              
+ n" r' h* p# f1 F      
, h2 r" N% N# e4 ?: |2 X$ a; Zfunction IsaNull(cCheck)         
( R& e% i; E  J+ B% Y5 x6 _: ] {          ! O. W7 P$ T/ y: l
return(cCheck != " ")         2 p% u0 O; m+ V  p" z& K
}                               - @/ ^* l( n  g" L' h; e
      
3 C$ P$ W" U/ A3 Nfunction checkform()     
% I4 H& v! V( _4 m5 I{
5 w4 ?. A7 H+ U8 {  id = document.sform1.id.value;     / F1 y! s- L" F+ b
if (id == "")     
, _, W6 p& M) Z  {     * m' B+ w6 T: ^1 b5 V
  alert("请输入注册名");     2 j+ M1 C( ?5 V# W! Q  j9 q
  document.sform1.id.focus();     
& n2 m# d+ {0 m  a1 H  return false;     4 a7 e; M6 u; t' b) \3 @3 @) t
  }     1 {+ c: n" o% U1 i
     
. h$ h1 ~+ Z# z# W2 T# w0 g for (nIndex=0; nIndex<id.length; nIndex++)     
4 p9 }1 t! G5 s! U  {     8 D4 u8 H- |, S- b5 f2 h% n) [- Y
  cCheck = id.charAt(nIndex);     
$ P0 j* s2 a0 n2 p) \9 L! Q$ g  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     , d( Q, B" C* J) @" u  H/ v. w
   {     # O. O+ z8 ?( b, [" ~
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
1 G- M1 o6 c7 F  x' M) [8 u   document.sform1.id.focus();     2 P  ^; {5 {. h3 A4 F7 ~
   return false;     , f  M7 F( P2 t0 {* f7 V
   }     # E; a+ E- A) o
  }
' `. Y# l9 |0 |5 ]! j- }  chineseid = document.sform1.chineseid.value;     + N* V5 G( _  I: r' J  W' e
if (chineseid == "")     
' U( |1 L/ ~2 Q  B  ], y, K4 S& w  {     0 P8 @- l$ a3 M( M; m- l# w
  alert("请输入中文昵称");     4 O" d$ K% T. d- N8 k& F
  document.sform1.chineseid.focus();     ) n% t7 I' f8 J: d+ E2 ^( n
  return false;     
( C. ]; Y) u0 h+ E& g  }   
# @4 G6 V  O; ^& y5 I password = document.sform1.password.value;     " C9 C9 Y% }" G& E( s' G' G
if (password == "")     # ?8 ]  O; r! b0 X2 u7 N
  {     
7 j5 J7 p2 _: U1 c  alert("请输入登陆密码");     
( Y2 S( j3 R+ S  `3 ?  document.sform1.password.focus();     2 O, a. `6 f1 M3 U' F
  return false;     
8 X9 ^. i5 b* a! s* |  } ! p' z4 Z" K& J5 c$ W
password1 = document.sform1.password1.value;     
; w2 a% K/ T! d: A, j; ~- h if (password>password1)     
" s0 m5 x& W. A) c2 r  {
/ F0 u: O3 w* S* {: h6 y     alert("重复密码与登陆密码不相同");     ! b0 z4 P, g$ Y0 a- J
  document.sform1.password.focus(); , d6 k# ~# M6 C6 W) Q5 F- }7 l
                                document.sform1.password1.focus();     
2 `. Y5 A3 m# X( M" P  return false;4 x5 ~7 Z0 g. T. M, r
  }  
( q) Z3 `9 l7 H$ s/ A4 C  dif (password<password1)     
5 \1 q# C: f8 j4 B- z6 _% x  {( d- L8 _6 k( ?/ g3 F( l& n, j6 W
     alert("重复密码与登陆密码不相同");     
$ d" m% L9 T1 y& {. {  document.sform1.password.focus(); * Z( `2 G8 ~0 F8 P5 c8 l$ |- g  G
                                document.sform1.password1.focus();     
9 t' ]8 s. R- f2 k+ e; B  return false;
9 z: c; Q) W& ]6 D2 q9 V( w# d  }
2 G) U/ m  s$ L if (document.sform1.email.value == "")     
  c5 g+ a5 M8 j) ~% |4 ~/ h, w2 V. {  {     
+ S( a; A; E( U4 r) ]  alert("请输入您的E-MAIL地址");     
! [: Q" r! R* m  s  document.sform1.email.focus();     
2 ]  b5 l& E6 L, |9 D# J  return false;     
" b: k6 g3 j; Q& A! ]# {$ F  i) L+ r  }     
7 N7 A" B- P2 }. s! _      2 l. v" }* ]2 x& V
email=document.sform1.email.value;      
! b! ?2 r. Y! K7 T emailerr=0     
  @* p/ T" L6 Z5 B" e5 b# c5 ~ for (i=0; i<email.length; i++)     , O: a; W. q3 ^; N' o  C& E
  {     
& \# G: {1 E6 w  if ((email.charAt(i) == "@") & (email.length > 5))     
" l  ~% n/ ~- K% @0 R" q. f   {     
4 C. z, q; m& d- @: u+ C+ T     emailerr=emailerr+1     0 }+ g* K$ x1 R& O. |5 y- o5 r+ ^5 w
   }     
' `% ?. H' }9 X* F9 L3 h8 k3 ?  }     - s- |- n9 e" ~  H! r4 R
if (emailerr != 1)     0 a. U4 B' `5 e/ |  h
  {     # D+ c( R1 B* A9 s2 V0 ?
  alert("请输入正确的E-MAIL地址");     
4 u. ^! a) J; `, n# I& W  document.sform1.email.focus();     : l) N3 ]# R+ m5 h9 Y) |8 ^
  return false;     * d* ?" _' D! t0 m4 a- P5 m
  }           
* Q; J) h3 u& L2 \1 h: Q& j5 @  ; N. N* f/ |9 s9 H( w
if (document.sform1.checkask.value=="") ) y) ~9 u4 U) P! W" U
  { ! m4 ~' s. D+ A5 L3 _; k& n% W* x' A4 `
   alert("密码提示问题不能为空");     4 t0 i2 |( f# ~% V/ ]7 n/ u
   document.sform1.checkask.focus();     ' x1 {( ^2 l* z8 C
   return false;  
* K1 p9 l9 h6 q, T2 T* }( n. W  }
- [! S7 w2 n; k9 G1 L6 m1 E if (document.sform1.checkans.value=="")
8 i& P3 s! U2 W5 z- r  { + a: r4 g* K/ C' l
   alert("您的密码提示问题答案不能为空");
4 l/ G5 z1 n6 S& J' G   document.sform1.checkans.focus();     ' F0 Q0 u5 {$ c- {' p
   return false;  . p' P# N! _8 }& r9 _7 q# a4 S
  }
- Z2 L( f  H/ J; O  m( r return true;     
% G- V" V/ F: O' \; \0 I( h7 ]" C) V     
+ O! U! t# ?5 t0 V' G' K- [7 Q} " i" d' Y, T5 v( s* w, @# ^  c$ \
</script>

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