返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
3 `! {/ d( B' {6 o$ s, f<script language="javascript">     
0 k/ d: ?/ e0 a9 ?9 Ffunction IsDigit(cCheck)     
- K1 j9 c& z4 \8 ~ {     
% I- |0 M& B) G7 F return (('0'<=cCheck) && (cCheck<='9'));     . e+ O* b, e. D6 f! Z
}     
5 F' C( P  W; T+ n4 \     8 \/ x: k% y  R$ f, N0 |
function IsAlpha(cCheck)     & n( F: w) A8 {$ A
{     
) m* U& Q7 D/ y: b6 _ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
1 [  ]( @7 O0 |' p7 j }              
. j. y, \3 H6 D2 [  d      / r/ O2 {2 J9 g$ T. W8 V
function IsaNull(cCheck)          # q, i' ^9 S6 L4 m! Q( ^4 }& J
{          ) y5 f5 q% R" I
return(cCheck != " ")         6 ~1 v- o* I1 a! t( M
}                               4 b8 Y( k$ R: ^7 j+ [: P; K9 C
      
" d7 s' x4 J4 B6 M( r8 _/ Efunction checkform()     + H1 [! W) h9 h; e2 r8 u$ X7 a
{ " O% M/ q! {- [4 G) G1 j
  id = document.sform1.id.value;     
* q# n0 u4 X, L3 v8 M if (id == "")     
1 {% w1 L9 }$ e1 d6 j* x  {     
6 h) @3 U1 [9 {3 G+ v  alert("请输入注册名");     
6 n: W0 H2 o* Q! k0 r# M: u) \  document.sform1.id.focus();     
1 n5 ?; i& P3 I  return false;     
; p* G/ q' B3 O  X. l0 p4 J( A  }     & p  b4 Q% S0 b& |% l/ A
     
" {5 Z  P9 [1 `+ J9 G3 `* R, O for (nIndex=0; nIndex<id.length; nIndex++)     8 r  k$ u8 s" O+ b7 W
  {     2 Z4 _7 h" I& `0 }9 d& ?
  cCheck = id.charAt(nIndex);     
# d3 E5 U7 @% z6 f  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
0 |$ ^* _' K, P9 B) K. ]   {     
8 q/ t) s, O# U6 B! f   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
1 ?) h; ~- a# H2 k' l2 p. C   document.sform1.id.focus();     
1 X% u, f9 P* @   return false;     1 X. v& `1 H$ _/ _- h2 k# l- k7 F& f
   }     
& D! R0 c& z4 G" G- ?8 a5 K  } % G/ n" H7 N8 i: o/ F7 ?
  chineseid = document.sform1.chineseid.value;     
, w0 b, U) e/ f" M; X! x6 m8 p if (chineseid == "")     
+ Q. z; k5 S! I" G  {     + w1 [+ C% ]+ q2 T
  alert("请输入中文昵称");     & p6 f* p" R3 l8 s* q- r8 {* E4 a
  document.sform1.chineseid.focus();     & W3 G8 }" I( |- z* p+ x4 ~! a  b
  return false;     
7 b3 J8 i  B, u) l6 K$ Q  }    5 A; Q, t# ^0 x4 i
password = document.sform1.password.value;     5 E0 n6 t! N8 w( Y* y+ V$ ]
if (password == "")     : e" w( w! N3 a  Y8 G
  {     
7 U! @5 t5 r+ L6 W  alert("请输入登陆密码");     
" P. T/ G. G* q  document.sform1.password.focus();     
* w$ R) E$ D+ V& B! g  return false;     
, H* V' }/ ~  s0 W: r  }
1 |4 b) I4 n% n4 ^ password1 = document.sform1.password1.value;     
+ G" ^8 O6 @: R( C: H if (password>password1)     0 T6 Q0 w  @; R' l+ \
  {
! `0 J2 r# @0 C$ O     alert("重复密码与登陆密码不相同");     : `/ L( }$ c5 \# x
  document.sform1.password.focus();
9 t5 f& p( O1 E& C) W/ q( S3 J- L1 W# j                                document.sform1.password1.focus();     ! b* F) p7 O2 P" M
  return false;6 s6 C3 }2 v: s6 Q% U" v/ H4 L
  }  
5 G' Y3 ~' y8 t9 |/ Fif (password<password1)     
" D1 L$ ^5 p: ~# ~  {: Z; I2 Q( V1 |: Y$ j" m% ]" Y& i
     alert("重复密码与登陆密码不相同");     # P& z; I% O1 d: A7 S5 U4 u
  document.sform1.password.focus();
8 {9 v# O, X1 z/ p: r                                document.sform1.password1.focus();     , t. O6 R$ b, p7 j
  return false;0 N; N% g& q5 [+ W0 }: y
  } 9 K8 p8 z2 j0 ~; b+ K$ C/ h3 j
if (document.sform1.email.value == "")     
" h" c4 ]' p/ B! j  W! f6 a  {     
1 T9 {! Y# g  ^6 l) j  alert("请输入您的E-MAIL地址");     
2 l& I( Q  N6 `) y- G  document.sform1.email.focus();     ) _7 L6 x1 R% r5 _, n3 U7 L% k# }$ }
  return false;     
; K8 m+ a1 V$ h. a9 L% V  }     
2 [6 K, i8 q+ J: v: R. }; e; |      * c1 ~3 R$ \/ L) ~8 D( |
email=document.sform1.email.value;      
, z5 p6 l( ~$ A+ M$ n) r; s emailerr=0     
0 w& H/ y7 w8 K: x5 j2 J for (i=0; i<email.length; i++)     
! ~( {3 g5 T) [' e4 X; Q- g  {     
; ^- e( ~: X& N* C/ B/ R  if ((email.charAt(i) == "@") & (email.length > 5))     8 @5 m" C. Z) y! a4 L* p6 A+ g; a
   {     
* y$ _( J. }- p     emailerr=emailerr+1     
' e/ X7 p& v+ @   }     
# c( o6 W: d8 f# y+ g! s  }     
/ y' M: W. ~9 h. M if (emailerr != 1)     
, p: U# j! n/ ~5 b9 u  {     # t2 S. V8 h3 l+ T
  alert("请输入正确的E-MAIL地址");     6 \0 ?6 u2 c8 M2 d9 B* f
  document.sform1.email.focus();     
1 g; s4 {+ a9 X0 U) m  return false;     & B' x$ P3 B$ ?, r+ }  e; }
  }           
0 H1 P' q7 H, t1 g! k) G$ {  
5 ?, A- p1 ^+ }0 k% O if (document.sform1.checkask.value=="") " W% q) \5 B2 l" g7 z) o7 M
  { 8 C. l) f, r0 V. p5 f! J
   alert("密码提示问题不能为空");     
* r2 q7 _+ V0 g+ w# j   document.sform1.checkask.focus();     7 ~, l: a- I9 O. q
   return false;  2 F# e# r+ I8 ^- F3 y+ ?3 `
  } 5 w& h( T2 z3 }8 Y- q, r  B
if (document.sform1.checkans.value=="")
$ X# P$ P( N* X! O  {
& T9 J: o, R( y. s1 q( s- A   alert("您的密码提示问题答案不能为空"); ) ^% @8 f; e/ h# |3 G
   document.sform1.checkans.focus();     
. r" D) o5 p  I0 E  y   return false;  
# k0 E+ _* J& d7 C9 ]0 a  }
8 q( J! z% n  u! Q4 R8 J/ `7 y- D return true;     ' t0 E3 W$ R( k  t
     
+ H: c6 w0 M1 x} . R7 _4 z, ^6 s
</script>

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