返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
2 p& M3 {$ K0 C+ Z0 g! G<script language="javascript">     
' N9 ?5 k/ g( D; c0 Nfunction IsDigit(cCheck)     , t6 v$ ~: _7 g4 M
{     
* I3 `! H# `) U* {! g6 d; u7 ] return (('0'<=cCheck) && (cCheck<='9'));     
# Y; K) R- u2 s4 K }     
2 _7 W3 g/ t, e6 a1 z( U4 u     
  ?5 z7 \( s% z! r. {; `! x5 \function IsAlpha(cCheck)     & I5 c3 }- K0 W1 s: |4 p
{     / H. S1 S5 u6 X  M8 y/ \: }: W
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     + X+ m$ u* d$ u: V! L& w+ Y$ ?
}              
& @5 ^  k( x. D& T      
) V  e) v( |7 g; |# hfunction IsaNull(cCheck)          - T0 A: v0 M. r+ y7 l" B& M% `
{         
2 [& S0 V2 N6 L return(cCheck != " ")         0 w  c/ b  G$ T* ~) Y
}                              
' Q' r  M" l( p5 h* o      
3 M8 d& F& S$ b1 h9 T& kfunction checkform()     9 E. y' L, E3 q) \" |
{
1 w) A. k7 P9 {7 ?  id = document.sform1.id.value;     
- P) G: `6 @) w- _- J: M if (id == "")     
  \4 c6 i, w, z7 `8 K  {     : ]' W- d, v! |; ^
  alert("请输入注册名");     ( |4 b) L) ^7 F: C' j
  document.sform1.id.focus();     ; Z: J, g& _5 r" q; A
  return false;     
9 c! Z' o9 o. {8 E  }     4 }! _; D4 ~( L0 E( b7 S' T+ s
     " f, M5 o$ X5 x8 Z5 ~" ^% e1 E1 R
for (nIndex=0; nIndex<id.length; nIndex++)     
. Y: ~7 _; R$ P. j  y4 d& N  {     # t7 P0 _+ c! w- R" w, |, A% j
  cCheck = id.charAt(nIndex);     
: z9 s! s; F# Y/ i" g1 r! H+ v  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     * K, u+ y! }; t  K
   {     ! s+ B6 m, [3 n$ ^0 U
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
3 @0 `) Z8 Q0 W4 C+ Q# W+ n$ b  F4 S   document.sform1.id.focus();     
3 g: f3 I: l, t' D# O1 K0 G' m   return false;     ) f8 o5 G% @& W" l5 t! s1 G/ I/ G
   }     " F2 ?; y0 K* {( ^: n% ~
  }
, ?% p8 \2 |2 @- e  chineseid = document.sform1.chineseid.value;     
9 v) }2 _! A9 U* _3 l if (chineseid == "")     
/ d, F/ k+ X( s5 {  {     9 ^% |- J! W; P
  alert("请输入中文昵称");     , D, t0 G1 Q& X+ I* {
  document.sform1.chineseid.focus();     
' q5 T1 E$ y8 a5 m/ |  return false;     
2 Y4 G/ R. j- o. A' K  }    ! [8 B! u. H. c7 i' V9 ^0 f- X' A
password = document.sform1.password.value;     % W1 Q  q5 l& s* \0 q$ f
if (password == "")     # h. L' B$ p! c1 D
  {     ; X# X5 k6 U- j) k$ Z0 i: e
  alert("请输入登陆密码");     
4 V$ M- B* M/ x+ a$ w3 A  document.sform1.password.focus();     
) F  B3 S5 A" M$ q  return false;     
, N& y5 M6 R% R) Q: _: ~/ C  } " P/ [1 O6 K7 @+ H+ n
password1 = document.sform1.password1.value;     
. M" q7 U. g& G  F9 X if (password>password1)     8 U+ q6 s0 x5 A+ P
  {
3 c, O' e& q/ K3 K     alert("重复密码与登陆密码不相同");     
# I: b* u. d$ e# k  document.sform1.password.focus(); ' e% O- `8 i8 m5 P- M" V
                                document.sform1.password1.focus();     
" {) \* ^' Z& N1 K8 ?' p1 R  return false;
5 `- x2 V* {3 [  }  
' \$ u, J; @( a6 J6 g1 d+ }if (password<password1)     
! y. y4 C, M5 ]; Z, i$ M/ K  {6 p0 a9 s, d9 h: E* q; L; X4 {
     alert("重复密码与登陆密码不相同");     
! |2 I+ }5 b3 ^* p+ G* ~) y  document.sform1.password.focus();
  P) f$ n2 d% `$ `. i7 p) ?/ q* O                                document.sform1.password1.focus();     - s" w$ @" x1 ?! h
  return false;
5 C: t( F9 q4 E( N% k1 M9 d  } $ B2 K$ I2 t1 |6 ~1 {. ^, h7 K
if (document.sform1.email.value == "")     & g8 m  J0 C6 i6 Q# k+ J. g
  {     ' O  T2 d2 E; J
  alert("请输入您的E-MAIL地址");     
2 Z. y# G  f7 F" j) _  document.sform1.email.focus();     
: J( I( t/ M* C2 u( s* j; [! H) R& f  return false;     
$ T/ l' {1 v. E  }     
$ e5 n5 T6 p) G( C# h3 g, E; K      * `% v7 d; W1 |9 R3 d7 c1 ]
email=document.sform1.email.value;      
4 L/ Z3 z! a# J emailerr=0     ( x1 o; p0 B, b1 [& C
for (i=0; i<email.length; i++)     : w/ H7 {4 a5 b9 M( U( z7 C
  {     
8 P* w: X7 C1 r0 r1 A  if ((email.charAt(i) == "@") & (email.length > 5))     , `) v. g8 q6 v& D2 J7 m0 l
   {     
" F6 ]; F. p) d9 P$ j4 b     emailerr=emailerr+1     
& X0 ]3 k* ?; }+ R! P$ B4 M* D   }     
$ ?" F1 I1 r2 H$ P2 k$ @8 S! `  }     
- c( `7 e: [. U7 F6 k8 l if (emailerr != 1)     & `- Z: p  L( g; |8 H
  {     
# B+ ?4 A- T# u8 P4 `3 \  alert("请输入正确的E-MAIL地址");     . `7 g) c6 v7 R
  document.sform1.email.focus();     ! H( I$ D9 S7 _/ Q/ O
  return false;     ) e2 l  S# o3 X' U6 L8 M- w
  }           
! K' z$ T2 `, s/ l7 _; S8 C* R. R  9 I" y1 M9 v/ B% b
if (document.sform1.checkask.value=="")
. D$ ?4 \& v% L' f+ O2 j  {
; p# U. Z) }. J2 X3 R0 C   alert("密码提示问题不能为空");     
5 Z* L, U( Z& [   document.sform1.checkask.focus();     
/ L% ^5 L1 t" r  O/ V* S   return false;  
4 _4 W* q& ]( E  } + v  B, D8 v8 ]
if (document.sform1.checkans.value=="")
( }6 H3 U* }* z! \  { 7 q5 C& f. q3 M: k9 x. o
   alert("您的密码提示问题答案不能为空");
% x- L3 f6 u0 r+ D* v   document.sform1.checkans.focus();     
- S$ t9 y+ t( v$ R1 j+ i" H- H   return false;  
9 j; N2 ^- \0 a* L# h  }
5 x: @4 _7 X/ V) L return true;     ' \' ~7 ]7 n9 q& w
     
& H2 u- l& ]2 p  \5 l}
1 Z: n$ l7 e7 R8 I+ Q' w</script>

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