返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:7 A  C5 S$ S3 g5 ]
<script language="javascript">     + d$ m; S& D7 i7 I' b9 g
function IsDigit(cCheck)     
9 w' r& K" j1 A* V {     
- I- `# T. m1 w; F5 b return (('0'<=cCheck) && (cCheck<='9'));     
7 p! e, Z7 E9 R7 e }     ' V  ?1 P8 A+ W6 R
     
# L$ F0 @0 h6 `! f0 Xfunction IsAlpha(cCheck)     / W# C8 b7 f& B- T8 F' d, a; q. @
{       d9 y; O9 i! L, C. N3 y0 |
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     2 B6 g/ Y) x# h& A# ]" t1 N) o
}              0 x8 c' K1 y+ [, ]. r1 P
      
+ `, A. |% ?' ], d2 V9 \9 B# G0 Bfunction IsaNull(cCheck)         
! k* P8 o3 Q0 q! D! T, I$ r3 q- @ {         
9 R5 {) E8 D, \. l0 B( k return(cCheck != " ")         - W% Q! y) w' K7 }7 \
}                              
- t4 j: o$ x9 y9 ^1 o* A. H      
5 X# z+ a9 h* o! E" |% [1 zfunction checkform()     
5 W/ `) k% F9 V) M+ e& G" _{ 7 U' c! Q( ]$ h! X. v  _# j
  id = document.sform1.id.value;     ; H: s  g$ R, y4 S0 \) C& V
if (id == "")     
, J6 I/ S  o7 z2 _' l. p: P  {     ; L- f' ^9 J7 u
  alert("请输入注册名");     
/ g! K" I2 o- f! S  document.sform1.id.focus();     ; ?, I+ w6 N+ K  W5 }$ V7 f/ m
  return false;     
& f! o- R% }0 C& m  }     
, }; S7 K$ p# B9 Y     
# R, d( d& ?  o for (nIndex=0; nIndex<id.length; nIndex++)     8 o7 S2 s& [7 W  b1 j9 o) \+ l. C
  {     . K8 h9 ^9 V5 |$ E
  cCheck = id.charAt(nIndex);     
* c1 }7 Y+ T5 e3 A  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     9 ?9 D& Z0 D. K8 z+ ?
   {     ) t5 l, @8 J( `" V0 n$ E$ d
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     - U  A5 X: q% e/ M
   document.sform1.id.focus();     
" r4 V1 v8 ?5 f1 m2 \  `# d' t; n' C   return false;     
* _4 o$ B4 h5 I   }     ( ^, ]$ z; U7 M/ I; I7 K
  }
* E9 \. W, b1 F" v* r5 V5 _) m1 S  chineseid = document.sform1.chineseid.value;     / `3 y( s1 J8 U( K  o* L
if (chineseid == "")     , N0 E8 H  `; l! \7 j( d. G+ }
  {     + i. k; t; H6 B" @6 P, S6 D( |, I
  alert("请输入中文昵称");     
5 w. Q( O# Q+ Q8 h6 J  document.sform1.chineseid.focus();     * L$ S& u5 E6 _0 \- E/ q$ S
  return false;     
. ?9 {( @5 H% N* B0 w  }    4 Z( M# b: g1 R. r+ A
password = document.sform1.password.value;     
% f5 k3 H: g" ` if (password == "")     
' P: V$ c' f& s7 |" W: l  {     * }! v( d7 t) K6 C1 a
  alert("请输入登陆密码");     
+ w- v2 Q5 f4 w1 K  document.sform1.password.focus();     ! d6 A. ]9 n1 [  K  Z$ L
  return false;     
: O' Q. q7 g6 h3 k$ u) e3 N9 ?  } . W* j  l. p0 f$ e
password1 = document.sform1.password1.value;     
! Y) E) U' y+ {; ^7 f; ]6 z8 e if (password>password1)     * g, f! W& B- _, m
  {
6 W7 c" ?4 }; ^. [$ M     alert("重复密码与登陆密码不相同");     
! \( o3 s: _/ e  document.sform1.password.focus();
- h5 U3 k4 M0 c/ s+ j) Z, e                                document.sform1.password1.focus();     
4 d. t8 D- b# R$ i1 @  return false;9 \% }! n5 ?* J/ ~6 {# i
  }  " ~$ S  h3 l- W) v- q
if (password<password1)     ( x9 n0 S( f* {/ c8 u8 @: D( T+ L
  {) S% G" e, W" \
     alert("重复密码与登陆密码不相同");     7 f# R1 s* }" A4 b
  document.sform1.password.focus(); ! k: `0 P8 z: b  ~+ H( U7 w. ?
                                document.sform1.password1.focus();     
3 b' G  {; r$ M/ g# z+ m  return false;: o8 R* V& O' D! f' V$ h
  }
1 [. c, X+ w6 Q  f if (document.sform1.email.value == "")     + a% M) i! O+ |& W8 r% V
  {     ) C8 c8 C0 ?3 e: d/ s
  alert("请输入您的E-MAIL地址");     + r/ R' U' p: [7 y* i
  document.sform1.email.focus();     * U1 U" H6 _( g$ F/ N
  return false;     9 r9 u) }5 _0 m# g* P' X
  }     7 w1 H; ]% W5 k  B
      % x  b1 ^* P9 d1 _9 d0 g8 ~0 f
email=document.sform1.email.value;      
6 v5 H' D  J0 v$ _& |3 k  N emailerr=0     
/ L( F0 y, L5 R3 ?, q" X3 A for (i=0; i<email.length; i++)     9 h& F% L# [( i6 g
  {     ) z3 j; ~' q: g- r1 D8 ~$ F
  if ((email.charAt(i) == "@") & (email.length > 5))     
9 \% H- U2 T# _0 f   {     9 D# R$ n* p3 K$ y4 ^$ G' c  [
     emailerr=emailerr+1     
6 G) \9 ]# W3 s3 ]7 B$ c2 O+ x   }     " m, C; o* t8 ]9 \8 Z+ z& O* b
  }     
$ r" `7 O4 ]$ o5 L if (emailerr != 1)     
( y& Q- A2 P3 }; Q' T) B' a# ~( z  {     3 v2 I+ m/ M( g- L
  alert("请输入正确的E-MAIL地址");     
0 S! d0 T8 s+ y$ e: t- C" y) Q  document.sform1.email.focus();     
' k4 X& t) D/ e( E# Q  return false;     
4 ^" I& w7 R7 a3 s0 A  }           " z3 E2 B( i" s8 a: L
  " A4 d' v% x6 M4 ~8 _
if (document.sform1.checkask.value=="")
2 h( I- m- {' ^: ^8 T4 |  @  { ! j; d5 [' P+ N- X4 V: P
   alert("密码提示问题不能为空");     ) f* E6 S: w: @$ G
   document.sform1.checkask.focus();     
5 C, n: H; z; K) P: A; Q$ r8 {   return false;  
# D- y+ K. T/ G# R' _  }
- v/ O, ~0 A8 z6 b if (document.sform1.checkans.value=="") 0 `5 X0 {! ^- `8 L; d& D
  { + Q$ [3 L5 S6 x) G, D5 {
   alert("您的密码提示问题答案不能为空");
/ {" q+ @8 ~, ~( q2 b3 g   document.sform1.checkans.focus();     
0 e8 g! S# a/ i6 b' H9 c2 `2 a7 j, l. _   return false;  ; L, t5 {% K1 b1 E  R6 ^" B
  }( I8 l/ t3 Z8 K; t. V* {
return true;     
( q. `0 a/ q& m! o/ Y     
) Z2 N5 y+ j! o% A" u}
4 B+ v& s8 l5 k5 ]6 f4 e</script>

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