返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:& q) e7 [0 j  g7 y# o8 O$ y
<script language="javascript">     : q6 _/ W2 W8 K: o
function IsDigit(cCheck)     ; N5 K1 Q+ c/ T
{     & X# G% P3 `  D- c
return (('0'<=cCheck) && (cCheck<='9'));     
- ]) e! e, c/ U- K! H# X }     
# e  S. ]/ O6 r  _- F4 W% k* e- k     ( A! t! h, s8 J* l8 D
function IsAlpha(cCheck)     * S6 u* u8 d6 Y, `$ d0 T0 e+ e  s
{     
" J9 c- F' W- E2 { return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
: ?+ E+ D. a# _  t }              
) p5 i* Z; v# c( }! @7 q2 H% \      
+ Z9 q: [% G& D$ A$ Kfunction IsaNull(cCheck)         
/ I. C# ~5 e0 ~! a1 N {         
9 ?5 g( T4 ~5 }1 h! l! F return(cCheck != " ")         
# k  Y& Z! h) ]* x  A1 N }                               6 `( m; M, T/ ^. e6 p
      , H) d3 h1 d. A6 W3 H
function checkform()     
- D. T( {6 x0 Q9 |5 ^* d{
4 b, _- S; M0 T% o( s  id = document.sform1.id.value;     
+ L; i2 ^: k, j( J. }, P! } if (id == "")     
8 I" C" B6 p- {# L" F  {     / [* V; ]3 J& C2 b% ~8 N3 K9 I
  alert("请输入注册名");     
7 v- j9 v+ ~) L: M  document.sform1.id.focus();     - Y( f2 G# I/ C/ K
  return false;     5 X* g  q+ l" \: h
  }     
7 c& H! G. m' d: m     
+ p. f$ e5 J5 ]2 \( }! |3 U! y for (nIndex=0; nIndex<id.length; nIndex++)     ! s! L+ J' t; I/ q. p  @) u
  {     
" ~: z" p6 p+ _1 T  cCheck = id.charAt(nIndex);       e$ X% P$ g: L
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ) ]' L% J# G1 Q
   {     
# T$ }) ^# Q7 i   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
7 }6 }% m* m2 C, ~- b2 C0 u, D   document.sform1.id.focus();     
/ T: _+ g- N/ @$ c! x7 ~# H   return false;     
3 {/ ]. t5 Z1 O) o2 q: `   }     
5 Q2 b* M9 c) v8 s) ^3 T4 L$ }1 e  } ( z% G. a3 x9 ^0 n# i
  chineseid = document.sform1.chineseid.value;     
2 i  l9 Z8 I1 s2 j if (chineseid == "")     
1 g4 ]; Z1 W& c3 ?+ I$ `  {     
' Y( D3 j5 }# q( ?5 ^, R; n4 B4 k  alert("请输入中文昵称");     
$ |" V' b" c) G  document.sform1.chineseid.focus();       @; E  U( `& F) U! S4 Q  L
  return false;     * D, K4 `/ J9 b" w/ J
  }    ! w% e. K: r& L$ Y+ S( ^
password = document.sform1.password.value;     # K$ n0 A7 [, Q3 _
if (password == "")     9 |3 j! R% s7 e/ f
  {     ' [1 j0 _, w  m/ U
  alert("请输入登陆密码");     
. N- J$ A; v, x$ V6 K" |  document.sform1.password.focus();     
' i, g, ~! G5 t2 l3 ]  return false;     " l5 h# R" r6 U) A
  } * [; f& ?; ?0 U" ~9 g/ \" u: ^
password1 = document.sform1.password1.value;     
7 h8 \; u9 q6 u/ ?0 q, Q/ p: B# T if (password>password1)     
! h" {# d! W% r. j* N" I. E, T  {8 P" r0 r. n9 M  p& f# K' a1 k
     alert("重复密码与登陆密码不相同");     
- t2 _- {5 z5 V" ]4 |% n' I3 ~+ E  document.sform1.password.focus();
# ^' U) W* I8 r+ v: `4 W                                document.sform1.password1.focus();     
5 [: E6 n/ }, }' m- o  return false;6 Y4 y/ J8 s( @/ t$ ^
  }  6 x2 D" i$ O" I/ G* g
if (password<password1)     
6 a# V- N7 d! M% j$ J/ v  {
1 t# @5 r1 o- K$ |$ [3 A$ H1 ~$ k     alert("重复密码与登陆密码不相同");     3 P% y2 m: e4 x* y4 @
  document.sform1.password.focus();
  s/ p, j* l" I: H) a0 Q3 X% g                                document.sform1.password1.focus();     5 U- X: r1 g4 N- o+ G5 A' x
  return false;
0 f# p' ~: |! o  } 6 {# @* ^6 H, I, M% ~1 k3 j* v+ `
if (document.sform1.email.value == "")     
  w. u2 B# A( H" Q, p7 J4 _  {     
2 d  ?% q) F) T2 {! O* N4 {  alert("请输入您的E-MAIL地址");     7 t) h, y. @1 ?3 J& }; b% X6 `3 j
  document.sform1.email.focus();     
/ o) ]% I. c) E  return false;     
% T& P; N: S3 n! C+ h  }     
6 W+ W1 _* g& I      
* O8 |' i2 U+ T# _2 U9 y! \# D1 K3 Z$ ^ email=document.sform1.email.value;      
/ [/ `1 ^. x7 l emailerr=0     
! ?: j+ r# o9 |5 b5 ^8 E for (i=0; i<email.length; i++)     0 x' J0 l# j. r- N2 w& b+ x
  {     2 n8 [4 R0 q. u) B! m
  if ((email.charAt(i) == "@") & (email.length > 5))     
: W( a, R9 O5 Y! a' g. o- X   {     , x) o: r. b: N
     emailerr=emailerr+1     ( R7 a" r0 ]% [" S5 D" Y
   }     9 b! M/ i; p0 u- C  j. M
  }     - j8 i7 b# |9 r$ o, t! l
if (emailerr != 1)     
5 k3 i2 |2 c1 p: L' V% s7 v7 h  {     
8 l% D$ f5 v3 q' _9 d- u; P  alert("请输入正确的E-MAIL地址");     
, [* g* l1 \& J7 z. O  document.sform1.email.focus();     
2 t: v6 T' x5 l% B0 ~' P5 }, y; C7 P  return false;     
+ W1 p  O: I6 S- P) r  }           ( b) C2 x2 W- d/ J
  # h( P# m& y! @/ }4 ~
if (document.sform1.checkask.value=="") 8 _% o: R3 d& l0 n4 H, |
  { & v" |" o% n& V% L
   alert("密码提示问题不能为空");     
) J3 c8 L; h5 M$ _   document.sform1.checkask.focus();     + l7 \/ X( Y1 v" _
   return false;  
8 x0 `# O" u4 w' H8 {2 H  }
* j4 Z  Q5 i4 I6 j if (document.sform1.checkans.value=="") : ]* _  @% g' u* I+ H' r8 x
  { 3 _7 l3 z  h2 l: ^' t) P: R
   alert("您的密码提示问题答案不能为空");
5 c$ ]% c4 R) ], w; p   document.sform1.checkans.focus();     $ H$ r6 @# }8 w- ^2 s' p7 b
   return false;  
) e5 b1 k- j, F- _1 b; S/ a  }; n8 C* l+ N# l2 a5 y) N
return true;     
3 B- B9 C0 g4 i2 n     , p5 [# |. z' u  m
} " n  g( e9 b/ u1 @$ r! B. _& `
</script>

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