返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
- ]* Y2 ~# k. W1 l& K9 p5 y% H$ U<script language="javascript">     0 L: P; G  v5 N# o& u' a5 {
function IsDigit(cCheck)     
/ `, q- E0 g- x. } {     
9 L' y  O; o3 j8 L( E' H( ^5 ~ return (('0'<=cCheck) && (cCheck<='9'));     
/ k! N( i: }' j) W0 R }     
+ V. d( n4 x: e  P% J4 I0 _     
+ \! K( r4 b8 ^function IsAlpha(cCheck)     4 v& e- h8 z! S8 t: A
{     ! V/ D9 J) z, R) E5 x
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     6 J" a' a6 t4 t. X: `& k/ [1 ?+ T" V
}              : }3 x& t" N; E. E8 D* W
      
$ _% a  @( Y8 n1 Cfunction IsaNull(cCheck)          % o8 y" S% l+ m- G1 X4 u8 `
{          ' p  G4 m- x/ |7 T! l' V
return(cCheck != " ")         
1 i9 ?) v' `  ?# }% [9 c }                              
( ^8 Y* L7 R& ]* Z: p/ a      
+ H+ a0 c. A* L: xfunction checkform()     - J9 D6 q+ |* q& S: {4 y
{ 7 V3 Y0 A6 M( l: A( Y
  id = document.sform1.id.value;     0 s5 N! A- p7 b+ H4 D: u
if (id == "")     
% W% l. j% I/ p1 l! c  {     * v2 M0 g( d& _) u  x. L
  alert("请输入注册名");     ; z5 I) r: ^* `: w( P7 a( E
  document.sform1.id.focus();     6 S- O; K& Z, p2 i8 r" ], |+ [+ L
  return false;     1 r$ J7 |$ j$ @7 Z: ^
  }     & l+ F  K# i) c2 I
     
' @/ T2 v) K% H4 n8 [- x( p6 | for (nIndex=0; nIndex<id.length; nIndex++)     - o$ X3 d2 q4 B& d" @4 f
  {     
4 ^( r7 I4 B" z  cCheck = id.charAt(nIndex);     0 l& _3 v2 l7 E1 G) ?
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     $ s6 z! Z( R5 h) T" C! C
   {     ; t2 l7 s6 S& R9 f. Y* I
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
' n: F0 L9 O5 j   document.sform1.id.focus();     / ?9 g3 Z9 X$ t. C: \5 x3 S7 f
   return false;     
) O) f  y7 ^7 P7 s   }     . j. z0 j3 X* k/ B& x8 P
  } + s1 |2 \2 m6 p! w
  chineseid = document.sform1.chineseid.value;     ) U6 S7 c1 [  {) ~" Q) t
if (chineseid == "")     
2 q6 }9 d( s; D  {     7 g- S* o) M6 a/ k( E+ K8 b
  alert("请输入中文昵称");     ; r+ M$ W& o1 u* H* p5 d
  document.sform1.chineseid.focus();     + a9 ^9 u9 ?6 U) V
  return false;     
4 b  h; Y3 y& ^/ ^  }   
, F! D+ `4 L  ]' n4 |! H password = document.sform1.password.value;     3 I3 P0 c1 k9 |/ }" L# h* @6 Z# g+ C
if (password == "")     
* K; W) r2 `& _* l$ U8 ^  {     
) N& v0 C/ [+ L2 g7 E6 }  alert("请输入登陆密码");     ! A+ r; R# \/ D8 r. H/ U3 n
  document.sform1.password.focus();     0 }+ N, K0 \6 r. H" l0 E
  return false;     " h9 c5 d# u& N1 x- r/ P
  } & @5 V, h1 S; f8 q4 W
password1 = document.sform1.password1.value;     & @7 R! Z' W1 x5 `1 G6 l' M0 i
if (password>password1)     " `& v! x" G) O* W
  {* T! a# h0 N5 T9 Z. G1 l; K9 w
     alert("重复密码与登陆密码不相同");     
2 L+ ~, e3 C' Y: `+ b7 I  document.sform1.password.focus(); ) H7 d2 y& [* e1 g8 V- p
                                document.sform1.password1.focus();     
# D( I8 Q5 [$ C7 d: _; z  return false;; l% J8 p: C5 O" R
  }  9 l' i; @# Z/ ?" S0 h  f7 d6 ?
if (password<password1)     
6 Y& W3 \) p& }/ v* E; c  {$ \' A% x6 l% }( p6 d9 S, l  |
     alert("重复密码与登陆密码不相同");     
" H& m9 u& o! V9 P  document.sform1.password.focus();
& X. y( ^# k0 o# r+ G: R                                document.sform1.password1.focus();     % ^4 N/ y. a* m5 V3 t) f' }
  return false;
+ h$ I5 o& @% p  }   e* Q8 E) H, E4 |
if (document.sform1.email.value == "")     3 `2 \" w  `0 H. i+ r
  {     7 Z. X' i, D" P
  alert("请输入您的E-MAIL地址");     
3 E6 f9 o( Y" I) k1 }  document.sform1.email.focus();     2 ^" L3 v% o' U. S+ S0 b
  return false;     
4 I: D; [; \  O  a& g  g$ r9 n  }     
* J6 L$ m; j% h. W      
+ W0 J6 u) ^$ U5 ] email=document.sform1.email.value;      
( b7 i0 M  {4 O7 s emailerr=0     7 N0 y9 x  M( _2 Z
for (i=0; i<email.length; i++)     
' C; q& S4 T$ D- i% t2 w6 T  {     
6 Q: p( ~+ z/ V/ A) B$ ]( p3 e  if ((email.charAt(i) == "@") & (email.length > 5))     
9 `" D; x: i6 I. V$ d1 h7 G   {     % ]( h- h$ v# M( T9 n
     emailerr=emailerr+1     4 v6 }+ F8 L4 {
   }     
" u3 `  A8 \3 s( V  }     ' Y# e) |4 d6 W* |% y( Z
if (emailerr != 1)     - T% R' p2 f5 f5 y) v- V
  {     
+ x& P! @- g3 x) Z3 z+ A# f  alert("请输入正确的E-MAIL地址");     
8 U% o9 Q; k/ v/ S  document.sform1.email.focus();     
% f: e% w9 R& c& V8 z1 g' ]  return false;     ! _% t' x+ Y/ l& U% Q! M
  }           1 k. N5 X- y/ p9 I/ E
  
+ j% f: }% E1 C( J if (document.sform1.checkask.value=="") + Y3 C- a0 W* ~1 L5 Z3 S/ L5 S, W
  { - a( N' U0 a& ?1 s9 L1 ]
   alert("密码提示问题不能为空");     
# O4 G7 d8 H  H/ Y+ L% J   document.sform1.checkask.focus();     
7 i7 u0 F0 P2 {, a5 a5 H9 _   return false;  
' s6 o1 s9 ]0 Y8 U" H  } + z( W6 e- ~1 V6 G" _
if (document.sform1.checkans.value=="") - l# r" A* l/ u. ]/ F! `
  { 7 A1 ^2 P( W" f+ v7 Y: z) n2 m7 S1 [
   alert("您的密码提示问题答案不能为空");
# R  k& U2 P9 X$ q: Z. ^   document.sform1.checkans.focus();     4 b" f0 y+ l$ P# s9 ^4 N
   return false;  7 W* h2 w) M6 t: s- f, H* t& ?
  }/ Z5 K" T& A2 C6 Q9 z
return true;     & f8 P( R9 e& e5 |  G6 N) k
     
2 q% K8 j  G# @} 4 |) j2 z7 c& |* i) z' @6 ]
</script>

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