返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
# ]: G$ v* s/ x<script language="javascript">     
5 O) d5 {5 O9 a+ Ufunction IsDigit(cCheck)     
: F* M: S: |2 X1 C {     
" _, i, S0 ], z5 @- f return (('0'<=cCheck) && (cCheck<='9'));     ) n1 }$ j; I) S  B& {, I& H
}     * s! b7 R2 T1 Y4 n+ T; `. m$ g; f
     
9 F( m2 L. F' M; i# p7 ^3 V$ Nfunction IsAlpha(cCheck)     
" z0 w0 Z' x# ]7 T7 `3 w5 R {     " l: }* A: S$ K5 Z/ X  K
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
( Y* F% u+ R, ~# Z" d }              
5 x) S( P+ y" f7 x4 y: o! b      
3 w% S7 I9 b, }function IsaNull(cCheck)            b! j1 X: Q& r+ ^& k/ F$ P
{         
* a! O8 _% V, `# |# u6 g6 M: H6 { return(cCheck != " ")         " ~5 t7 Y$ s& y! n9 O! x
}                              
1 i' U( T" j3 Y6 I$ \      . Y; O! k0 u( X1 C' [9 D6 y; t2 k
function checkform()     
# |3 X# [/ a6 X2 F{
2 D. T3 U( T% {# `) d7 a$ M  id = document.sform1.id.value;     - m! _. z' `9 }. m+ X2 F
if (id == "")     ) a2 J3 E5 r! @  _$ C
  {     4 h; a) Z- k: N/ x+ c
  alert("请输入注册名");     
1 U7 M# Q; b+ u" S  document.sform1.id.focus();     
$ `( h& [( F( X3 [* O* o2 J  return false;     9 i/ |& C7 |5 J) m* c
  }     ! q) T5 [% k: h' S/ b: r
     
' o; E% c& h- d2 C- O; d" U for (nIndex=0; nIndex<id.length; nIndex++)     
7 x0 T! Y6 o4 N& X2 p+ I  {     , v3 ]2 l& i( t
  cCheck = id.charAt(nIndex);       b4 ~( D9 P. q& w( J: l
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
0 K( k+ n$ L  s' p   {     , h, ~' n/ s% R# f- W! [3 g
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     % O* ~$ z1 u+ k1 @' v! G
   document.sform1.id.focus();     ' E: A' C  q' D- [5 ~3 Y+ _
   return false;     
* f! R9 H/ T3 e$ |6 V+ B   }     : N6 B7 h1 s" ~# D7 K8 V5 E
  }   [! J- p0 c0 w5 x( U( \+ N, @" j
  chineseid = document.sform1.chineseid.value;     
* }. D# d" b6 }5 k" ]4 ] if (chineseid == "")     
5 r. J. J% j1 \, W7 e' X" k  {     
  ?* K) W& J9 u  alert("请输入中文昵称");     3 Z6 T4 f2 M, q+ C7 A6 ~
  document.sform1.chineseid.focus();     " Z% I# e' g8 B  X
  return false;     5 o8 u# B5 t! y- U
  }    , w! G1 |, s$ {
password = document.sform1.password.value;     ! z0 U5 G2 T) G! `: n* b( U
if (password == "")     3 ]) |6 `. o/ O$ Y( m0 v
  {     / ?6 x9 @- O9 p
  alert("请输入登陆密码");     , f% j  I+ H2 g1 H3 C
  document.sform1.password.focus();     " }6 m8 r4 [9 N  Z5 j, {2 X! o) D
  return false;     : A/ i) z2 @4 f/ ]
  }
% o- e6 i8 n/ K* A password1 = document.sform1.password1.value;     + W8 F! `& O7 Z/ x# r' n" Z3 l- G/ f6 I
if (password>password1)     9 |+ h* s( L' k' i
  {0 u4 D7 @; J9 u8 V$ Z- O. P
     alert("重复密码与登陆密码不相同");     
& B- \# P" s4 [1 K" g  document.sform1.password.focus();
* {( D. N  a! |' ~0 u1 T                                document.sform1.password1.focus();     
' c+ q% \1 B/ K  return false;
! x# c0 A9 g% f% I# _1 ?  }  & @+ B* i# ~7 q: u' ], ]3 s7 m
if (password<password1)     
7 [, b: s; i: \  {* j8 r* f$ x% y5 Z" b* S; M* K
     alert("重复密码与登陆密码不相同");       l, E* p( v: B0 L$ S
  document.sform1.password.focus();
. h3 b) ]# W8 h$ L8 w                                document.sform1.password1.focus();     
  R- c* ]* v( t+ u  return false;9 z" ^4 t1 Z1 M# V$ \' s% H1 C& M
  }
5 |! A2 Q: ?! g" H$ s2 D5 N6 v: X if (document.sform1.email.value == "")     
3 O# o( V( n# o  {     . n9 a; E& I! P' u$ L' _
  alert("请输入您的E-MAIL地址");     6 y( ~, p0 e6 b8 p  t
  document.sform1.email.focus();     
  c; x3 x2 U( K# i9 v  return false;     
0 ~4 K8 L! s. r6 U$ N" \  }     
: u6 i3 g4 k  A" a      8 P8 r" `* _; t: P& |7 F; }  R( k+ }
email=document.sform1.email.value;      # s" |8 _' @' M2 f9 G" c
emailerr=0     & l- g$ d$ C6 c3 ~- k: M! Y; T
for (i=0; i<email.length; i++)     3 L" s5 `5 _) |
  {     
0 z3 Z. `$ H) G8 Q- B4 y  if ((email.charAt(i) == "@") & (email.length > 5))     
3 E& v6 c+ f4 H/ a   {     5 B, [9 ~7 e! S+ y% x/ t+ n
     emailerr=emailerr+1     
6 _5 D1 B% c2 v   }     
* C/ D5 d( }7 J3 R. U% S9 I  }     7 `$ @2 D% [8 j. C. ^
if (emailerr != 1)     
7 C' [- V; W+ _3 P- f; M* E! X  {     2 L$ G) K' |8 D5 W  R* G
  alert("请输入正确的E-MAIL地址");     
( H8 ~% b- I: |, o( W" w  document.sform1.email.focus();     : [! s* b) W  J
  return false;     5 d" v8 I0 b, w1 P: ^" s
  }           " C) [( A) D, a) Z5 j. [( X; I  w! M
  
' w3 R# `  O: v3 a! R if (document.sform1.checkask.value=="")
$ L& M! B6 E0 ]9 P8 F  { ) ?$ J9 ]4 p8 ?0 N+ P" C5 x# r
   alert("密码提示问题不能为空");     
) y4 R7 R: T1 a6 c/ c; F' n   document.sform1.checkask.focus();     ! P4 w8 |1 r/ h' q. l2 G) b$ w' g
   return false;    \# R' P+ b' p
  } 8 p/ I, L( h: V0 a7 l
if (document.sform1.checkans.value=="") ! d3 C" X6 n4 [4 w& n5 v
  {
0 A; K- M- M1 @   alert("您的密码提示问题答案不能为空");
- S* [7 c  r: O   document.sform1.checkans.focus();     : f# J: U3 @) x2 a' S' F
   return false;  + H7 W% E/ o) a/ \) ~
  }# E! y( p; [% X7 y0 E
return true;     
' n/ R, t4 S$ d  e/ D' @- ?# q     8 E7 d& |9 K) Y5 q  I" K9 P
} / M7 T8 f" ^9 ], w/ e, G
</script>

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