返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
, e* F7 }+ M9 J) \# L9 N<script language="javascript">     
, ], L; T) p& L+ A" u, Cfunction IsDigit(cCheck)     4 O- p! J; Y$ ]5 W
{     8 F$ c% j9 ?6 }4 M
return (('0'<=cCheck) && (cCheck<='9'));     
/ a' M% S2 c4 {& L  b }     
# B) [6 r9 Z4 f     
; \  p0 P& \; efunction IsAlpha(cCheck)     2 D2 M2 ~4 r0 _+ K7 g
{       f) E! F2 Z% P7 ]# r
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))       [: g& ~' x! p& O
}              6 S0 H3 Q1 F! e; ?
      & w1 V, ^' d0 s0 M; h7 i
function IsaNull(cCheck)         
$ m1 f4 o! x+ M$ g {         
, Z& ]; Y8 Y' i9 M2 O return(cCheck != " ")         
6 k1 I# G# z* i# G }                              
4 ^% V4 p/ X6 S% ~' }$ V      $ S( {- s- ]& x$ q& J+ Y
function checkform()       W8 v/ R5 ^8 a7 W$ V8 j$ W4 x7 s
{ 8 p# p& k2 q6 d. S7 v1 q4 w
  id = document.sform1.id.value;     $ w3 ~6 f8 n3 K+ C* j
if (id == "")     0 r1 Q. {6 X) e9 S& P3 I  S
  {     
1 r: G6 K9 H4 I: S, V  alert("请输入注册名");     
' r. o1 _+ b1 t5 E7 o) X  document.sform1.id.focus();     3 O9 x6 |# F8 Z) X! W+ t
  return false;     
) D6 d$ b$ o' V7 f4 G4 {  }     
& L# g3 W3 `% d' T* F$ E     
4 \+ B) q4 g3 u) U2 ~ for (nIndex=0; nIndex<id.length; nIndex++)     
3 E" U- v4 C. j* t$ A3 E, N  {     
0 o3 s# {5 p9 {  l( [  C* g' Z! c0 a  cCheck = id.charAt(nIndex);     
$ s3 w3 Z% {2 w% i' `% l% {; l  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
5 s1 Y$ X# O+ G7 ~   {     
& t; m0 \5 a+ v+ }   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
. b) I# ~5 i+ G4 p1 y+ S3 C  X8 V   document.sform1.id.focus();     
' P% ~$ g! C/ x5 ^3 b/ z- ^8 i: _   return false;     & i1 c& U. `* k: p% b
   }     5 u. s$ j) z5 e; e4 j
  }
5 `0 w0 V3 l, `) g: y& A  chineseid = document.sform1.chineseid.value;     
  X. I$ T4 k3 S; f/ h if (chineseid == "")     
- v& Z. s, }7 w2 }  {     
7 Z: V! h4 ~. M: a- B/ _: h  alert("请输入中文昵称");     
. b4 a4 H' U+ f! k  document.sform1.chineseid.focus();     
9 W" G8 b" S" G2 d  return false;     
. ]) r: T: s$ {) V/ D5 e  }   
0 S) c# d9 ?; g password = document.sform1.password.value;     
$ U- A# n, [7 \, o, n7 N: ? if (password == "")     ) x. R% v* V) ^
  {     0 y  M# v' `2 s
  alert("请输入登陆密码");     * U& B8 s4 S4 |2 h1 @
  document.sform1.password.focus();     6 F; ^2 j, m- ]  a0 m
  return false;     ! ^( K3 G* ^, t( A: _. B0 b
  } - x: o% ?" T1 T- X! j
password1 = document.sform1.password1.value;     & w, ~' C9 ]& v" z" N1 E) t5 w
if (password>password1)     
0 M! x/ Z' s) k& f9 r  {
( }7 v6 j4 {+ X: V) ]     alert("重复密码与登陆密码不相同");     ' o; J2 s) C0 ^: ]4 _/ M
  document.sform1.password.focus();
& Z3 G# f  o* N" j4 B- ?                                document.sform1.password1.focus();     
) V% l" l% I9 E  ~# @) W  return false;& p! Q0 d) n+ D3 W$ C! S
  }  # g' Q$ C# l3 ^+ x
if (password<password1)     & \8 D, U6 \4 U4 @% n! V
  {
; m! q! A3 i+ Q- A* l3 F     alert("重复密码与登陆密码不相同");     
% c2 L3 U' q2 C5 K  document.sform1.password.focus(); % B+ J" O# o4 w: x3 _
                                document.sform1.password1.focus();     
8 u+ O( i; B9 c; t$ {  return false;
, D  Z1 J; p% j( }  }
6 `; a) K8 C. ~1 u; `, o' V if (document.sform1.email.value == "")     7 u' e! P8 p- R4 e/ c
  {     
0 ~' V5 t: f# F4 E/ Z  g  alert("请输入您的E-MAIL地址");     1 G4 v  V) J- d: [: q' W* S
  document.sform1.email.focus();     & @, b# W4 I0 ^
  return false;     
6 s: e. m0 h+ |: _- o  }     0 n8 t- ^4 r+ A! a
      ) K( {8 @4 H% {: F; S
email=document.sform1.email.value;      
" K% R/ v  q* {  `$ ~# N emailerr=0     
4 G3 Y5 `. p$ L8 K  M for (i=0; i<email.length; i++)     
/ a9 S* ^) B5 b7 ]7 y. Y  {     1 p4 d4 c- O# \* `: T( T
  if ((email.charAt(i) == "@") & (email.length > 5))     
. E" F7 o, g; f0 P( F% ?# f! V6 g( l   {     + K0 @! O5 L6 D: R& C: J
     emailerr=emailerr+1     $ L# K$ V9 y3 {& D
   }     : U! \+ o# m9 _( v( P
  }     
) x( s  P; w- U9 p. W5 O  [ if (emailerr != 1)     4 K' q2 `5 u: ~& r
  {     / h2 A9 p( M7 ^- k. V
  alert("请输入正确的E-MAIL地址");     
& t6 q9 _% b0 r  document.sform1.email.focus();     . ?0 J9 H# a- m* F6 _
  return false;     6 n  K! c6 D. b8 e: Q
  }           
5 q9 U7 G( f  _) w5 [  7 h. v: W5 D. w7 r  N  y2 X  O
if (document.sform1.checkask.value=="") 6 T; G+ W  F% z% e
  { ; _. Y! b/ R2 I* P
   alert("密码提示问题不能为空");     
( A  X) C2 }& Q4 j2 B   document.sform1.checkask.focus();     
9 G0 c: s" Z% y   return false;  4 l( N# {% z& \/ s
  }
# G5 h. P/ ]+ I7 G5 E if (document.sform1.checkans.value=="") 8 |1 @# f5 _; U
  { , p6 E# i% U1 `) H& ]
   alert("您的密码提示问题答案不能为空");
, L5 z3 C# y4 }  ^   document.sform1.checkans.focus();       W1 D, o9 A6 {. }' O" E
   return false;  
. T, w2 a1 K+ ]- ?5 L! j5 O1 S  }
$ M2 y3 I4 |/ x0 Y/ V return true;     $ n% C9 T1 {* y, C+ {5 j
     
1 r5 W6 f4 `+ r; h  @, m}
, n2 r# O: I& J) O; `</script>

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