获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:! P8 `: X' m" R0 U1 S
<script language="javascript">     ( T% L# U9 y" b2 w% g! s
function IsDigit(cCheck)     ' K5 g2 j& o2 z7 e: E- H
{     
; t' I9 A6 x) p7 y7 k return (('0'<=cCheck) && (cCheck<='9'));     0 t+ ]; e/ \3 |9 q, g* v
}     
: N/ g- S' ]* U  j3 k, i# M     
& P0 X. M9 S7 efunction IsAlpha(cCheck)     
+ Z% v. H. D( a& a5 x {     * `) E) {, J" K0 A  H0 i) H2 {1 F
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
! P0 l# O+ Z- Z. j2 Q9 {$ B }              
* e5 J, L+ e* y& v      
# k; {! v4 T+ lfunction IsaNull(cCheck)         
' }/ Z4 \/ l4 J& q& \2 f, K {          , p8 c! X; h0 s  U: G
return(cCheck != " ")         , [6 X0 Y  I: p  D6 ?) {
}                               # X4 h, N7 I. K2 o7 I( {
      
0 c3 A2 |7 z, k0 {* e* s) s( Mfunction checkform()     : F1 z3 z7 S# C1 Y' |* J
{
! s; B; @; _! V! @( g. W" W8 Z* _4 U  id = document.sform1.id.value;     - u" t$ u& G+ o: ~: m) p' o) |/ c. J6 ~
if (id == "")     ; l8 Y( B3 k9 g
  {     * a% M% Q" K- f: M
  alert("请输入注册名");     - ]$ c+ ^6 W2 i8 c; V, E. i. [( N5 W
  document.sform1.id.focus();     
# F8 ?9 I  h! {% @7 q. L4 F  return false;     
  t( |1 g4 i/ u1 l% S  }     3 _! C/ a5 M; j& ]8 l
     
2 m5 a& R$ u; g  L# t' c for (nIndex=0; nIndex<id.length; nIndex++)     ; p$ j3 i- J- K" ^, ?0 N
  {     & y+ _# X4 e( H1 H
  cCheck = id.charAt(nIndex);     
5 O3 m5 [8 p/ p1 Q. ^( C/ w  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
( W: j$ ?% G6 K+ c/ h. S   {     - j. @- H7 P( u% U) {8 a) M
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     + @' C9 h" F1 h
   document.sform1.id.focus();     
+ d+ r# {6 T9 h' x5 I6 h2 V   return false;     
4 y1 c, t; x) j  f# M  ]   }     6 A4 @: q. I5 w2 R
  }
- N- j5 H7 e8 C3 D) t* J% ^  chineseid = document.sform1.chineseid.value;     
9 e6 w" @3 j& y5 s0 X if (chineseid == "")     ( r0 Q8 T) _- _. p* G
  {     
/ c( h. j8 }" x6 D) H  alert("请输入中文昵称");     
' j2 {2 U6 k$ B2 l  document.sform1.chineseid.focus();     
* I2 T: L# I" Y8 @  return false;     ! i( _7 q  ], D/ l: w
  }    ! `& M6 X$ `& o8 q
password = document.sform1.password.value;     " k& ]1 D  L; }  Z: M* F% S
if (password == "")     5 F- Y, [7 U9 U
  {     $ Z1 D% K3 y8 e' N
  alert("请输入登陆密码");     
. O7 \" s+ _, y1 `& q  document.sform1.password.focus();     
4 T/ E! U* O2 u8 @5 i! F; e  return false;     8 }" ~0 t6 J# T; n( f! v6 O
  }
' u- @% ]" n6 D password1 = document.sform1.password1.value;     
) S7 C' h  X! M# D# G if (password>password1)     # [5 X! j# J9 B" o! i4 G
  {
0 f( L( m; t' I2 Y  y     alert("重复密码与登陆密码不相同");     5 V5 A/ q- d* ?6 [5 s
  document.sform1.password.focus();
$ n6 K' g% k4 f4 P+ U                                document.sform1.password1.focus();     
' v7 @: j9 C) Z1 y" r  return false;, [8 Z6 a6 T$ b. `- ?
  }  
0 w5 z. f* u) s. oif (password<password1)     9 i6 e! S8 x1 C; q/ D1 a
  {
5 s) @' [. c3 S7 Y" Y     alert("重复密码与登陆密码不相同");     
9 X  G! q8 v/ m: N4 }+ k3 s/ F  document.sform1.password.focus(); $ Z+ i" @. n) ^3 P9 e
                                document.sform1.password1.focus();     
' @: r, {8 j/ n; }3 |  return false;  b7 o% c  ^6 B, x
  }
3 ]- g: l7 b9 X. ?$ l if (document.sform1.email.value == "")     
/ B$ N# b, n8 k- }9 f7 }  {     
% |  o4 K7 W' O* B' e  alert("请输入您的E-MAIL地址");     $ y% _$ T+ \/ P  p% g6 Q
  document.sform1.email.focus();     + o  b" P4 z4 ?- J7 [$ B6 D' ^
  return false;     ; x9 t9 q4 U0 W& x2 J8 t
  }       r2 {1 F# E7 s3 i
      & v2 P1 T0 q/ M! ]% Z
email=document.sform1.email.value;      
% X. Y5 v7 d  U: X1 c1 U4 X emailerr=0     
1 Q5 g9 ?4 j7 H2 t6 T  t for (i=0; i<email.length; i++)     
) [2 G/ c+ H$ W. t- @+ V( d3 g$ C  {     + {. v: A* z1 g8 X! E
  if ((email.charAt(i) == "@") & (email.length > 5))     
; c5 f. K7 a/ U# i# t7 t   {     
$ O( k" U( `* }2 b( y     emailerr=emailerr+1     
" g+ Y9 r  E( v# t   }     * y* I4 f+ U7 |
  }     
0 ~+ Z% u; }7 v: C9 I if (emailerr != 1)     2 l0 L- o& H* R' T( K0 X! c$ i; W
  {     0 k: p4 h9 f$ s5 Y& e
  alert("请输入正确的E-MAIL地址");     
8 M1 `6 q$ A( d* q) }, D  document.sform1.email.focus();     
) Q) D0 P0 l! W( |* H1 d8 d1 a; G+ U  return false;     8 i  m  r& W" P3 g+ v2 f. |+ V
  }           0 g' F  G! f- J
  
  W# @& R6 ?: T) @ if (document.sform1.checkask.value=="") 8 `; O% Y# h# N5 X% y3 H
  {
0 }, S/ @3 W& G   alert("密码提示问题不能为空");     8 l: r/ b+ `5 H1 ?5 k% U! g& g# C! j
   document.sform1.checkask.focus();     
# Z% t- m8 @# j3 C( y   return false;  + ~* p" h2 C& C5 _' S# P7 [
  } : a. R+ J; o2 {1 i" j
if (document.sform1.checkans.value=="") , R4 }9 n0 b) b- Q/ c
  { 0 F: a4 B% ]! c" L, z: q
   alert("您的密码提示问题答案不能为空");
, X6 |" u0 m5 H   document.sform1.checkans.focus();     
9 i* y5 r* h2 h, P# E8 a8 U   return false;  
5 e0 h" F$ R  j+ ^; @7 L+ J* E  }/ D% l, b" z( B
return true;     5 e, ~2 `; D4 \+ b; D2 P
     : p. S$ h" o0 _$ Q9 @3 {
}
: D) A' H/ v$ i5 Q- E0 O</script>

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