返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:7 B, ?0 l# a- y4 L. v( R1 V( \
<script language="javascript">     4 R4 t; D- j1 t1 g2 b4 I2 W+ P; S
function IsDigit(cCheck)     + @  O4 f% @: ~% Z3 v/ T: V4 b
{     % }, p% W2 H) i& v3 X% Y# c9 L' J
return (('0'<=cCheck) && (cCheck<='9'));     + r4 r# g% h! I+ r" M
}     0 D  J' e. P' R" G
     
# b0 n8 f! R9 qfunction IsAlpha(cCheck)     
4 o& z3 Y8 R8 w& u1 _1 s) {4 W {     * u8 l2 j! _9 g
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
; b$ r# ]' m- V( F" x }              
5 e- c) ^+ H' M3 |$ I8 ]0 i6 j6 ]      5 J: U$ e3 X! g* U0 k7 I  [. y
function IsaNull(cCheck)          - z1 d, v# O3 X+ H( q' W* l
{         
0 D6 D- c' i1 b; P; M$ k! ~ return(cCheck != " ")         , L* }( A# i$ ?  @, W1 L3 K
}                              
6 ]: T3 X0 [+ Y8 ?  b. y. E      , D. r* E; a3 M7 v, Q) w
function checkform()     
7 F0 i) k! T( e. f$ H1 _: Q, w{ . w5 h/ p3 W( d0 H6 a# _& h
  id = document.sform1.id.value;     
) i8 q, u# x* E) m0 q4 P if (id == "")     
5 k6 U% }0 d- {4 o7 H5 G  {     " w- d& T/ B5 \( M$ x  l" S
  alert("请输入注册名");     
) l; h1 k: d. j. _  document.sform1.id.focus();     6 B1 K/ u" I! r6 i. p! ?
  return false;     
# T% e; V: ?5 j- A1 c& r* ?+ j( C9 M  }     2 }, N! k" ^- D2 y
     4 j, I, c3 S# h) R/ o& o) S3 w
for (nIndex=0; nIndex<id.length; nIndex++)     
7 _- H7 u. \2 _9 k6 [  Q  {     3 m" J  _& _. f+ }
  cCheck = id.charAt(nIndex);     
8 M0 w, B" p- M' v& U7 [  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ; }) D9 d6 `) y
   {     0 G! Z' e2 V9 O7 Q+ ~) x
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
5 [  @  K! ^, f   document.sform1.id.focus();     
' ~! P5 c" g/ R/ Y# x- i6 q+ A   return false;     
7 j* e" r& `) y7 e. N+ }/ I: T   }     
& U( Q% a: p) W7 V  }
0 `% s7 O- S) ?; q  chineseid = document.sform1.chineseid.value;     
4 ~( V( s2 C7 `3 X5 g if (chineseid == "")     
( |8 j( k9 [. G8 l' m, I  {     
9 k( b2 w4 G0 a+ d* m! c  alert("请输入中文昵称");     
# E  [5 d" |1 N  document.sform1.chineseid.focus();     & C1 @2 q, N% W8 x& A
  return false;     
% C( J1 A# k2 f  }    2 T! u4 i; }$ b+ u
password = document.sform1.password.value;     $ a* y7 i' v9 W$ J! T2 @6 Q/ L
if (password == "")     
4 t  }! L3 t+ P! k! x. k; R  {     
6 R3 t; F! E7 ^( ^( |( ]  alert("请输入登陆密码");     
8 K2 R  c. L* K2 Z/ n( m/ r0 c  document.sform1.password.focus();     , x* F+ k% ^; [  H9 e6 [
  return false;     $ E3 i0 j0 J) y9 f8 }. I
  }
. f+ K2 l1 X4 k password1 = document.sform1.password1.value;     - v7 h: e/ B1 |2 w
if (password>password1)     1 N( _, u8 m7 G3 j1 L' N0 @
  {, E$ w' V" ^/ O$ X- r8 ~0 R, \( L
     alert("重复密码与登陆密码不相同");     
5 S. M/ m% `$ s) F: x0 i2 e, K  document.sform1.password.focus(); - g$ J+ }4 T- N, o" b% r
                                document.sform1.password1.focus();     
" G" U$ X# ~! `) ?* Y* l  return false;4 [- j) E# g- I" N3 ]! ~- l
  }  
, k! `/ t; C6 G' M, S8 b" Yif (password<password1)     
4 m4 h7 G' z) h+ Q7 m4 S  {$ q% ]4 J) c: T! V! `* A$ Y. U
     alert("重复密码与登陆密码不相同");     
( L. g0 Q( ]7 t  document.sform1.password.focus(); 1 P: W  F( C* L6 j; `) `  R$ i
                                document.sform1.password1.focus();     
8 ]  V! |7 O2 M6 `& g  return false;0 a: I9 L3 X2 x: t& c
  }
# v: S' W# ]' H0 q5 _ if (document.sform1.email.value == "")     
2 I6 Z( w: q9 G  {     
4 `+ k% [& h0 K" A. ^  alert("请输入您的E-MAIL地址");     
, R' X$ j  e$ S, }. e, u/ i( L  document.sform1.email.focus();       l% J9 s# r' x- Y8 h3 ?. I
  return false;     
( k: M7 a/ e: K. g# d  }     $ J. d9 l) d. V8 I
      - S7 c$ l* n3 ?0 O' N
email=document.sform1.email.value;      
5 o; w+ k8 B4 L% E' K; W emailerr=0     
9 t% _  t; r& u0 I for (i=0; i<email.length; i++)     
  D- J+ g2 g7 |, Z' |7 V  {     8 H7 Y) Z' M2 z' s& b! _. C
  if ((email.charAt(i) == "@") & (email.length > 5))     
$ Q; z" v/ K' ]7 m   {     
/ }7 d. E* I( z2 q1 b     emailerr=emailerr+1     
9 I& Q0 ], ?, \) A  O! N+ F   }     6 e+ s- E8 |# I
  }     " W8 f; H% Z8 q
if (emailerr != 1)     
- g) l" T2 m& ?+ j  {     2 _4 Y/ e* o6 a( o! }# L0 M
  alert("请输入正确的E-MAIL地址");     
# a; M: y* z$ j  document.sform1.email.focus();     
) Z9 c# f4 a! H% o" w) ?* ^* E  return false;     
8 k) f2 K% ?9 K& P3 g  }           
; r+ t% _4 S' P, I$ d( S! O  
" W# E2 k- I1 i7 I+ g; T9 o9 } if (document.sform1.checkask.value=="") - j% H( \' W8 u! `$ L5 Z
  { & S# ]. _& R% ], j+ P; F- ]
   alert("密码提示问题不能为空");     , @3 w+ f# c# r( N& \" Q* Z
   document.sform1.checkask.focus();     / R! G9 Z$ W& ~! \, H. Z1 L
   return false;  + s1 D# o+ @4 A7 A9 l, e
  }
' {/ d% t: C: x if (document.sform1.checkans.value=="")
2 ~0 \% \1 ^0 f- X1 A( A  { & l7 Q' W$ ], Q* p! D( V
   alert("您的密码提示问题答案不能为空");
0 t# ^5 @$ f" s6 Y   document.sform1.checkans.focus();     ( o; A* K" v# y  I) n! Z' Z- G* @, H
   return false;  
# S% I2 _: e& M3 `5 G  }. Q6 _: I) T3 Q9 W
return true;     + @2 q0 Y7 B1 b9 s, g
     ' p. e  W/ Y  a+ A, ^; A1 ^& a+ d
} 1 z8 S9 [$ e9 b1 e6 L9 A
</script>

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