返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:& h! I4 [% a* U
<script language="javascript">     
# o2 k% N- ?' w8 ?& @function IsDigit(cCheck)     
6 A0 @9 w7 o: a4 c- G# M {       q1 G4 `" ?9 x9 N) i
return (('0'<=cCheck) && (cCheck<='9'));     
9 O/ i* n& ?. d5 ]6 {% f8 H }     
( w/ x" m9 x6 @7 M+ Z. A+ L     
: C* ~% J) Q) B4 ^function IsAlpha(cCheck)     
; D8 B" B4 Q, y4 c' f  v  w {     
! E: L$ T# D& C9 r return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
3 z) J4 L& `* g" w. O }              
) I, @/ i' p4 O5 D4 Q" e      2 z& X( _" n  S# R
function IsaNull(cCheck)         
* n* m8 d9 _( I7 ~7 c) \' X {            [  s/ G& L. h* x8 g
return(cCheck != " ")         
) C; a& E* z3 j }                               2 K/ X! C, G) O/ B
      
2 W& n" Y+ D/ Vfunction checkform()     ' X/ t+ ^! U: Q7 L# W2 O5 `
{ 1 [0 c2 i: Z& T4 F5 V. X5 C
  id = document.sform1.id.value;     
1 c! y  @# e  ]5 B- ~. P if (id == "")     & P+ r, V, b: c) g' u/ W
  {     ' E8 S8 i, X# r  h3 x8 @
  alert("请输入注册名");     ( V/ I7 P5 n7 B" P/ I) d$ R
  document.sform1.id.focus();     ; l1 Y7 P: k+ I! ^* d7 ^; T5 e
  return false;     6 t5 i/ R) [4 r% I8 r) @
  }     : j" S; W+ C4 ]' x" ~% M
     : k1 j* g4 y4 @; M
for (nIndex=0; nIndex<id.length; nIndex++)     
5 A' f( }6 s! l  F. {6 ]; g  {     ' G! w( f8 c9 a' i8 c* j, o
  cCheck = id.charAt(nIndex);     
/ a8 s" n# h5 f' i  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
, I* P# [8 \+ v  v: `   {     3 u7 J, h% I) }$ _$ y$ S" Y
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     * i( ^; M. a' U+ s1 d0 k
   document.sform1.id.focus();     5 s+ j" ~8 P+ y& C$ b
   return false;     8 o; c$ o& M% R: ?$ P
   }     
* j5 [: c0 _. e: M+ O- X  }
/ q  G! L* m, s4 j, C# e  chineseid = document.sform1.chineseid.value;     6 ]( G) {) W) N
if (chineseid == "")     ; h7 i! K: d: A
  {     0 ^, m: E6 p  R0 I9 _" ]7 ~
  alert("请输入中文昵称");     ; B# u! I* p4 q( d8 J
  document.sform1.chineseid.focus();     
& w& S9 @# B/ D7 J! `  return false;     
, x9 V8 k" U- \2 x! e* m  }    4 l1 Q2 j' a1 S3 [3 @2 Z: F
password = document.sform1.password.value;     % A# s6 z. u  y6 @' q& g" ?
if (password == "")     3 }# m3 F; E( l, u" u
  {     
9 T0 b# J5 _- Z) U* v  alert("请输入登陆密码");     
. P0 q5 y% u4 Q/ h2 U5 {* C0 L  document.sform1.password.focus();     
7 ?7 R8 p, F3 e. H2 V3 o8 f( H  return false;     . f6 ^$ }7 {9 ]8 b6 o  K
  } ; s/ M' W/ S5 Z3 N3 l( w8 F
password1 = document.sform1.password1.value;     # O9 w0 J0 m) C% ]3 z7 J. u  z
if (password>password1)     
7 O4 z* }# J7 @  {
* Z* R& W; n$ o/ w5 p0 M( Y& @     alert("重复密码与登陆密码不相同");     1 H- r+ y# J2 P8 P+ ?6 `
  document.sform1.password.focus();
5 l* d( O/ U+ C8 k  @9 \' @                                document.sform1.password1.focus();     
- q5 D  D! [# b  `9 B3 A* S  return false;# g$ X9 z. R. j+ o& V% d9 b# X
  }  . z' G$ F' {+ x8 B6 ~. [
if (password<password1)     ) d+ {8 T/ o% x7 y) n2 H
  {
$ t* t* R4 ~% ~9 e: p     alert("重复密码与登陆密码不相同");     
; [+ Z7 x# W' k5 n' n3 V' K  document.sform1.password.focus();
- }4 c$ S9 f" x                                document.sform1.password1.focus();     
; D  ?# ?; J; V% X5 t  return false;6 @. }# C7 c  T, `
  }
" r" Q) T# \# W, U0 _: s, W if (document.sform1.email.value == "")     ! D/ \4 Q' u" v  }: ^; O
  {     9 ]0 |8 {3 q0 P" _
  alert("请输入您的E-MAIL地址");     
' R4 D0 K! H9 z8 ^6 d/ o7 j  document.sform1.email.focus();     2 P* B8 f: t1 H, l
  return false;     $ `/ V8 h* {0 o6 H1 ~) l
  }     
- y. d# ~) {* J$ Q$ B. G      
* N1 v. x0 g+ A& L9 j! H* a! L# X email=document.sform1.email.value;      
3 F1 R- t/ n# l, Z( ?: ?5 N emailerr=0     2 H) S) C( P( f; q$ V
for (i=0; i<email.length; i++)     " H+ i0 R7 U2 l9 V& g$ C+ |
  {     ) r. m! b7 S& G# B- v. }; ~( e1 S: c7 F
  if ((email.charAt(i) == "@") & (email.length > 5))     
9 _/ C. s6 g  p3 [   {     
  r" P" h; u1 F! {     emailerr=emailerr+1     / [, r, N, U6 _& x9 v
   }     
5 d% v# E; V2 `. f( Y  }     4 K7 U% t6 W2 ^) L
if (emailerr != 1)     
( O8 y# [  c$ D! K( }2 W) y  {     
1 z9 [  n. c) ^' r) C5 r  alert("请输入正确的E-MAIL地址");     
  ?7 z( L: [* {; p6 i, V5 z! K6 e8 i# z, I  document.sform1.email.focus();     
6 c+ M0 w* Z6 j4 Z1 K% a. L  return false;     
( {! v' c/ q% B* m. G. ~  }           
$ J. V9 P. v% M+ k  p: W( s8 c  
1 B5 _7 T% v' A8 L7 ?" j$ } if (document.sform1.checkask.value=="") 7 `6 `% k, E& @# w9 m+ q- W; s
  {
( k" i9 S6 j) t8 H1 J( f   alert("密码提示问题不能为空");     
# G0 d& ?) k4 |' g2 m# D$ Q   document.sform1.checkask.focus();     
& m: I7 r+ _/ @2 D* \) l7 J   return false;  6 g  f, d' B* _6 G
  } 4 l) g+ Y$ T, `9 I( z
if (document.sform1.checkans.value=="")
2 C8 D3 K. X6 w2 R7 X6 a8 _, }  {
. o* ~. ^* Z, a0 [8 k0 g   alert("您的密码提示问题答案不能为空");
: P3 e+ B' \/ S6 R0 v) E/ q* d   document.sform1.checkans.focus();     
  d. v7 ^2 f7 P# ?+ I! M- l; ^  S! n   return false;  
, }, A9 ~+ ~2 ^' A( G+ M  }9 ~' Z8 i5 s; a9 t
return true;     
8 ^" w1 A3 F8 t6 U: N) Z     
. e3 q9 t, \7 w. \$ N}
" a5 T9 ]3 b* U5 [8 U0 S</script>

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