返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
7 P$ Y6 ~2 W6 s: v3 a<script language="javascript">     . s6 Q  T& o  M+ i. @1 q+ G; M; ?! ^
function IsDigit(cCheck)     9 l9 _- H/ A# p, ]
{     
/ C1 H; t: x3 b return (('0'<=cCheck) && (cCheck<='9'));     
' c2 M( E$ v, u& s+ A. D }     
. U" Y: A6 J: w/ i4 T. K4 Y" ]     . _( D( @$ {0 `5 x1 O3 z4 I6 v' n
function IsAlpha(cCheck)     ) _- J  Z/ ?: c( X4 ~* r9 T
{     
, t8 }7 ]$ ]' Z! E3 v8 p5 g& i) X return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
7 v1 I7 \& Y. u0 O) B7 _6 S$ c( S9 P' x }              : f; a* t. H+ }( H7 O  A4 y
      : T) T1 Q: T1 ^; ~7 j# p
function IsaNull(cCheck)         
) }7 s  h1 E# s! Z) K {         
$ R; a6 R" X" j8 ^+ p! [ return(cCheck != " ")         / o6 y! k) ~7 o; N
}                               / A5 F- }8 n" F( S& A
      # F/ G0 S1 K4 K, Q; f4 O
function checkform()     4 O2 R) I% e" |% {, E  B
{
  n# }2 v: W& D; M1 E  id = document.sform1.id.value;     
- r4 O: V! y, c if (id == "")     
. R' q5 E' |+ `) j! Y2 ]  {     * z" ^  P6 z7 w8 ^& x: L
  alert("请输入注册名");     
4 U1 f) x9 S  Z- h  document.sform1.id.focus();     4 N7 L. P9 J9 Z8 w, E' k
  return false;     
: E. V2 }' h1 t$ L* w' l( G7 _  }     7 B  {$ m% s4 D# ?1 {
     
6 p0 o/ m7 m/ k0 c& A for (nIndex=0; nIndex<id.length; nIndex++)     + I/ w* V7 F+ P% S
  {     - D6 W; W1 k3 \
  cCheck = id.charAt(nIndex);     3 h# F7 k1 j# r' q) P; i6 n4 A
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     - O! R6 k, r# l
   {     
9 e) z9 u- Y4 x8 s   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ! f9 D' H' \7 m( f
   document.sform1.id.focus();     
' H5 F( h" ?, d4 K   return false;     
5 f1 k9 C+ }! y9 R   }     8 ~. _2 G& R4 {; C' ~" e/ |
  }
; a  ]3 q  Z2 a5 [/ W1 W4 i! m  chineseid = document.sform1.chineseid.value;     - p* h% t9 Y" H. e
if (chineseid == "")     
) }# T8 f5 m# d- ~' a, n  {     9 h, P( f* K# M6 }+ C
  alert("请输入中文昵称");     " b" h' c$ @6 E4 m$ f) f# y
  document.sform1.chineseid.focus();     / ~! r4 B5 Z! ?6 r1 n. S
  return false;     , e+ @) k$ e; m! B6 |" k
  }   
4 W* c& a2 f* |  V password = document.sform1.password.value;     
$ V4 ]9 N7 E* U  H8 O7 T; y5 b if (password == "")     
) u* w; T; W4 _2 D. F  {     & j! \' ^7 p- v2 x5 O6 F+ e9 O
  alert("请输入登陆密码");     3 o1 d3 }' @! J3 T+ K) ?: a+ n/ e
  document.sform1.password.focus();     
, [; T! M% ^3 a5 n8 g" i  return false;     : @( l. \6 J/ [( l1 i3 L6 r
  }
5 T* K4 e4 {  R: r( x password1 = document.sform1.password1.value;     5 p. p% G2 k. b( {
if (password>password1)     
% W- _/ n7 n% i8 X, @  {
- y7 x1 L( [& b: d: t1 ]     alert("重复密码与登陆密码不相同");     
& J. `2 c3 n4 W2 O. \  document.sform1.password.focus(); 4 M% k( I  M$ u7 d. W' F
                                document.sform1.password1.focus();     
. G2 [$ x" q# J" w; B, F  return false;' f6 D' ]* L! m' H0 d, V8 l1 X
  }  ! h5 \& G4 f, C  b* {1 Q
if (password<password1)     
* E7 X6 f$ {4 L  {( }; x$ F1 u5 S+ D
     alert("重复密码与登陆密码不相同");       d& t; c! C( o3 K5 P
  document.sform1.password.focus();
1 \& d3 c0 q9 e: d; J- D                                document.sform1.password1.focus();     
. k9 [: m5 |& \  return false;
/ W% V  g3 P( u& R  }
; r, R4 o( l+ s/ Z4 L2 p if (document.sform1.email.value == "")     + h# q) I% G7 }/ ^# f8 J+ [
  {     % k; J7 `" Q+ x; l9 o6 e6 a
  alert("请输入您的E-MAIL地址");     ' O0 A! P% Y  ^( ~1 M3 [
  document.sform1.email.focus();     
8 N0 {0 ^7 I$ j& Q  l* z7 L  return false;     
$ `5 c+ w: X) i6 C" d; h  }     
" i( \4 k7 i8 R0 u& ]9 V- r      
$ V3 x9 X/ k) E9 _ email=document.sform1.email.value;      
. d, C# t3 e8 Y; a; R- d8 ?4 I emailerr=0     
5 k  \  h2 d2 p' c& W+ z- x) a for (i=0; i<email.length; i++)     
  t0 G* ^, n* U  L& l5 F! `5 ~8 Y/ _/ R  {     
' r) x8 c1 m$ I* _$ T  if ((email.charAt(i) == "@") & (email.length > 5))     
8 c+ A5 `; i  w/ _: v3 X   {     
- c# {+ b/ a  p, e6 m- G2 N* N8 l/ q     emailerr=emailerr+1     : F; I) x' A7 W7 D% Y) X
   }     
9 ?" G5 y4 d, b! I( q2 f  }     8 ^! y4 H6 T, ]8 y: L) N7 w
if (emailerr != 1)     
. k$ s" A4 a2 N  {     
6 P9 a& i6 z3 V3 G; F3 X  alert("请输入正确的E-MAIL地址");     4 Y% w1 i9 n) `7 c# v3 c
  document.sform1.email.focus();     & f& B8 h/ K2 H* n3 R+ l
  return false;     $ C8 W% C; v$ ^+ V5 U& @% J- \
  }           5 e/ V' G) Y6 \$ K6 y8 N, T5 U
  
. s1 S! n2 ~6 b8 C* |( F if (document.sform1.checkask.value=="")
: c! L2 h  B1 b2 @$ R$ [3 _  {
2 h% M/ L& c9 |9 M   alert("密码提示问题不能为空");     $ L% e' y. X+ S0 B" s
   document.sform1.checkask.focus();     
% A, k" i; S# d( H, e; u# ^4 k   return false;  
: b' X: z5 z: F$ K  } 2 D3 q: b2 }; T2 K8 c4 C$ {7 q
if (document.sform1.checkans.value=="") 1 |! D, w: A' y1 L/ r
  {
2 K) ~8 ^7 R" J  ^% x   alert("您的密码提示问题答案不能为空"); & f  X+ ]) A( O: f
   document.sform1.checkans.focus();     ) z4 n6 A1 _5 a7 G# u$ W' l
   return false;  
% R. E- a. Z* F( I  }. ?; C4 j! K$ n, E; Z( h
return true;     ( ]* u- B. ~: G& {7 F" P
     
6 o, k3 v! E1 `: N- a9 f" k} 9 h6 W; L. U8 N' P. k8 \5 H
</script>

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