返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
' c0 G% q3 Z+ M; e<script language="javascript">     - l+ n+ F) `9 W3 I# s
function IsDigit(cCheck)     
3 _& R0 P& [( p: a' p: N& e {     3 c- Y! K+ b3 E* R7 U1 `8 _0 I
return (('0'<=cCheck) && (cCheck<='9'));     
$ Z% ]2 l) X6 a7 Z8 b; `0 f+ u/ w1 f }     
% \# f# w3 t3 j: A5 r       ~/ X0 R3 }$ j: `
function IsAlpha(cCheck)     / v' b- }; R  S) L  @) B5 U/ N2 X
{     
  y2 v& f; m  [2 i7 p. I return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     & ?  r& @8 Z4 M  c: m2 {
}              1 l5 I. L6 X3 w* t
      
. o2 g1 X& _/ ?$ z7 |0 kfunction IsaNull(cCheck)         
3 }1 A* W* e8 k9 W {          7 f! I! w: r$ @9 G$ x
return(cCheck != " ")         ' L$ ?& _, Z7 K1 F5 S* E7 s
}                                 s5 F/ b& v* S( a* k% P$ |, C
      3 i. D$ c  A( {# X: b
function checkform()     ' Z- X3 s6 z0 G8 X% b/ @' f8 [
{
/ R+ t+ }8 p$ L; V7 I* m6 b  id = document.sform1.id.value;     * F1 X, v! X/ R1 a0 @8 M+ b
if (id == "")     
7 q9 S' Z6 s. T  {     ( F1 O# E; v2 S2 P' T4 u
  alert("请输入注册名");     
  R. i9 @4 @  w6 k0 _  document.sform1.id.focus();     " s# s) A7 ^8 V# t2 \" z
  return false;     
6 U) T% O, F, r$ Q& v  }     2 Y; ^( o9 r+ L, E. X9 i
     
8 }5 H) @( d1 v8 I1 _+ Q4 I for (nIndex=0; nIndex<id.length; nIndex++)     
0 S$ d, t* U* D# b: s/ F, y  {     
% c/ w. w7 y, S% j) K6 u  cCheck = id.charAt(nIndex);     
  F- G$ B0 {& {# `  j  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     , h4 n$ A2 ]% {! o* \
   {     
  G2 t, p4 c  y2 R% {5 @   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
% z  t! c+ m5 u) x! z+ E   document.sform1.id.focus();     
& m) M9 y; o1 R7 g- e3 i0 ?   return false;     $ u/ R8 u4 b3 U; k' J
   }     6 a/ b# ^& b7 Q% m# X0 f1 H
  }
8 O! B3 W( K. }4 h  chineseid = document.sform1.chineseid.value;       V; v) O2 y3 \3 @
if (chineseid == "")     : n0 c( N& o# ~) i0 n- s
  {     9 G: O$ a0 u- D
  alert("请输入中文昵称");     ' ]' h, m6 y6 o9 z9 L6 j4 z
  document.sform1.chineseid.focus();     . q0 n& N! z, v+ m$ w
  return false;     8 e. @( p$ b# T& F
  }    1 [1 T9 I9 U8 i6 S
password = document.sform1.password.value;     
4 K8 t/ @, L* z+ ?8 U; R; n7 M if (password == "")     
8 U" k" e+ m! \; P7 r- h9 Q  {     
! j$ K) x. z% N: c  alert("请输入登陆密码");     9 a$ w) V  j7 ?5 z/ R- z) G
  document.sform1.password.focus();     
" \" t% M9 I3 b) S3 t# A% P  return false;     
2 @1 L* m# S( Z* C  } 5 `$ u: H( p0 U8 L! N1 A
password1 = document.sform1.password1.value;     
8 w4 g' B9 ?! B1 j; R; K8 \- o, u* Y1 K if (password>password1)     2 D1 j8 B  R" ?: s
  {" s$ N4 l: w' d+ P
     alert("重复密码与登陆密码不相同");     
! W* f1 i9 ]5 r, M: d% ^  document.sform1.password.focus(); 3 Z- f7 ~# J. {! a+ d1 M
                                document.sform1.password1.focus();     8 R7 M2 c6 q% }" U. P2 f
  return false;
5 L1 s- B* S: C  }  
" z$ `, p% C3 y2 Lif (password<password1)     ( m( n  V/ @! R1 e4 U6 |1 v! T
  {4 I9 S  }- W& J& a* }- h0 R
     alert("重复密码与登陆密码不相同");     
2 J( D6 ?: j; ?# {5 s1 Q: V3 b( F  document.sform1.password.focus(); 8 r4 E. X' j) ?5 l3 g8 M5 `! a/ v! s
                                document.sform1.password1.focus();     
+ ]' t8 w7 `7 C( u  return false;
# s+ c' R) x. _3 U- c  }
+ H6 N+ w) `9 ~! P5 _) |: F. { if (document.sform1.email.value == "")     1 |( w: a5 C5 O! w
  {     
! l) o; _+ W9 V0 Z( ^( s# x* o  alert("请输入您的E-MAIL地址");     7 @0 Z  R3 M$ R7 h% s: O( A- {
  document.sform1.email.focus();     + I0 e3 U$ v% I$ M8 ]$ y/ u" C( U
  return false;     
% z, @/ k% W# W4 u! ?) L  }     
0 \  Z6 Y8 `  i& y0 g7 F/ J6 w% o6 }      4 }- F0 J. W3 ]1 `, @) B, h5 `
email=document.sform1.email.value;      
6 u! }* i( [% Z& H: ^6 V5 S, } emailerr=0     
# |; d6 J& p( l; H for (i=0; i<email.length; i++)     5 R* Q& r% Y* k) s; C2 G% S" P. t1 B
  {     0 a6 c* r6 g: F- Z
  if ((email.charAt(i) == "@") & (email.length > 5))     
6 {* R& K1 n. h2 e   {     
6 L$ R5 }/ X' l2 W1 O/ \     emailerr=emailerr+1     
) }! f3 E  t9 g+ V9 D) h   }     
$ t7 z* P) l* o3 F* P  Q  }     5 l! u- `! N; d
if (emailerr != 1)     ( B0 a0 Y: T7 \: T4 Y
  {     " m7 B: v( z# |; n% C
  alert("请输入正确的E-MAIL地址");       }, G- G; |" j" |& u9 y
  document.sform1.email.focus();     : U3 g( q1 D7 m! N) b2 c
  return false;     
/ }5 L8 m, E7 `( r  }           
# n2 n9 z  _; l% t- \9 K! j) m; _  
2 ~" s& h! V. A" @3 t' J if (document.sform1.checkask.value=="")
/ H5 E& W. C3 p8 M- V  { % l9 w. Y2 I: q' G
   alert("密码提示问题不能为空");     
6 h. e. d3 X. Q% G5 _   document.sform1.checkask.focus();     6 h) U, s+ o9 w0 D1 _. p
   return false;  + e' \& W! t& K" @& C
  } 4 S5 g$ @  P( Q% _( A* o7 m3 V# M( ~
if (document.sform1.checkans.value=="")
7 i3 D) a: x6 g9 P6 p5 q2 j  {
: o7 @2 y  n* F   alert("您的密码提示问题答案不能为空");
% j- {& c* L3 j0 W, t/ r   document.sform1.checkans.focus();     
/ x+ p' `0 t/ J* ^6 |   return false;  
5 j1 u8 {0 A4 `+ p- j' Z) G  }/ c" m4 f  Z5 L* L1 {9 d
return true;     
6 z4 m4 B3 o2 Q  m6 r6 P, z     5 `6 \5 W2 Z( a7 k- n; N" F
} ( q/ P! @+ K; T/ d/ g
</script>

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