返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
6 L+ i" u3 n1 ]<script language="javascript">     7 ^: G0 {+ Y( \3 x7 ]7 {! y  ?, E
function IsDigit(cCheck)     
  E  Q$ W! G: @4 Y4 _1 E8 } {     
! w& A4 r( U0 C) }# e return (('0'<=cCheck) && (cCheck<='9'));     
/ x. A! j7 c, m. D# Z) ]) z }     
" r; }2 g, f5 |  X+ W0 [     7 |+ U, J. i" U$ v! b: K" }
function IsAlpha(cCheck)     
  M. r4 l: `" e# J& d {     
" g0 b' y, I4 |3 A5 x2 I  ] return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
) S0 O/ c% A$ n2 @ }              + l; Q$ {# X4 x1 K" I
      - U* f  A; G# Z" l: S& g  E1 o3 u
function IsaNull(cCheck)         
+ j1 T: _" ?/ g' {" S5 `! }7 `- ]0 e {          3 T$ ^0 {2 S" G, @. r  _
return(cCheck != " ")         
: L% ]& _, e3 s7 T. l% n- c }                              
0 m/ f( |8 ?) q( K2 V5 \      
: ?$ V' j& K7 g7 u/ ?# q* K( Ufunction checkform()     
6 O; H* G. V, J7 F% t1 R2 H{
) Z, W: m5 k2 W, T4 X/ e2 b  id = document.sform1.id.value;     3 G: Z3 m6 h8 X9 E' l+ y% r: V( [
if (id == "")     : a. d! R* e# P7 [
  {     
( O* ~; {0 F3 m, n& U  ?  alert("请输入注册名");     " d1 |, n  e% ^" E
  document.sform1.id.focus();     ( i/ {. S* D7 U# S+ P: V
  return false;     
/ j; [. R8 u: u+ E# ]* v5 _1 L  }     
9 p; r9 s8 r0 @3 N$ k+ q     5 Z' t! B8 \( b  i9 b$ z7 m3 G/ e
for (nIndex=0; nIndex<id.length; nIndex++)     ! T3 ?' X+ L5 z+ O4 O0 W* h' t
  {     
  p1 b& m  r5 A2 k& V8 O  cCheck = id.charAt(nIndex);     / ?: p6 D* i% ~  @  ]) J% l* ~
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
4 i, ?3 O' `  d. t   {     , a' P' \+ H+ O. y: ~
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
3 K5 U$ G. M1 N1 y9 F& x   document.sform1.id.focus();     
  A) P& _; k% j' d1 v) n2 a( I   return false;     
" L2 G% K4 M2 B7 R+ L/ A7 f( K9 V4 l   }     
7 T9 f7 W+ p6 ]( |  } # _6 Y* L. J' `
  chineseid = document.sform1.chineseid.value;     . i# M) d+ p! {5 d) T0 R! z
if (chineseid == "")     : w/ F# Z$ X! x/ f
  {     . |0 ?4 L. R. k8 `
  alert("请输入中文昵称");     2 K9 _/ M7 B* F  o4 Y! M- b
  document.sform1.chineseid.focus();     , Y2 \$ L( ~+ l5 x/ E
  return false;     
5 ~* z+ a+ m7 n. H; {" z# v5 X! J  }    & s4 V$ G# h: t( i% c
password = document.sform1.password.value;     
. b6 j7 x2 q# C  l( T0 i6 H if (password == "")     
7 q% t4 w5 x8 A2 i  {     
+ |3 K) D7 y" J  [/ @9 l3 |! `  alert("请输入登陆密码");     / z$ ]3 l$ K$ Y% o
  document.sform1.password.focus();     : H- E1 Q- l3 d4 l: B2 ]$ O
  return false;     
+ f) L; _2 I/ m  }
$ [! `7 O$ W7 [1 H password1 = document.sform1.password1.value;     . f% U8 l4 ^: |: l) n
if (password>password1)     ; Q  r+ p$ M9 n/ I8 |
  {
5 `! L+ G* g! j; h. N     alert("重复密码与登陆密码不相同");     
# J' T, j2 X1 L8 ?4 M  document.sform1.password.focus(); ) f, a3 K9 Z  J9 O7 T$ e- M  n' x/ n
                                document.sform1.password1.focus();     . \! J# j* O3 o) y9 ]
  return false;1 J8 U& x7 w/ z% C# |
  }  " |8 `* _! o5 F! w3 X6 {9 J
if (password<password1)     & F. J2 P2 c$ n  A
  {
7 D. g# m* C3 \7 Z     alert("重复密码与登陆密码不相同");     * ^. L2 Z# _# ~( _: ?9 [" p
  document.sform1.password.focus(); 7 _9 @4 k7 Y( F' Y; z8 M3 |! h
                                document.sform1.password1.focus();     
3 I: M) e& \3 G& Y  return false;
/ I, K9 O) M2 Y) ]0 W/ V/ j- e  } $ ~: W1 y0 P$ s4 k- c# H- w
if (document.sform1.email.value == "")     
: \# G( ^  h& V, u( T: I  {     ! s8 a. E4 R8 @# b8 Z
  alert("请输入您的E-MAIL地址");     
$ o1 f8 v, x  O% N  document.sform1.email.focus();     0 o* ^- J( n) T& ]8 E
  return false;     
9 J. l& @; d; o+ s4 U  }     
/ Z* u6 J. X) m3 O7 Y- L4 U      
. @9 Y5 b  a- j: O- _ email=document.sform1.email.value;      
& c/ t6 h+ J. U- D3 J# A emailerr=0     / I, p/ s) D! k3 K
for (i=0; i<email.length; i++)     ( s; q8 y( u5 F. V; S
  {     
  R8 c( u& d4 H5 L7 _& y4 h  if ((email.charAt(i) == "@") & (email.length > 5))     2 x; L! M  @: T% }! `( G6 R! j
   {     
/ m* A( @: t0 k+ q- ~% X- s; ^     emailerr=emailerr+1     
+ e4 W! e4 Y3 u5 |   }     % Y1 i; o3 e# V- C: ~
  }     
8 P. c3 e3 B' V( T; H, e if (emailerr != 1)     " U* n* S) c% `  b$ v8 L$ T
  {     6 d& ]; J0 g3 l) G% Q
  alert("请输入正确的E-MAIL地址");     ' ~2 B, x& L0 g; q$ ?
  document.sform1.email.focus();     
6 l5 U  H' t- K9 N1 M0 f. q: }  return false;     
6 W! z- S/ a0 F( ^' O" j2 Z+ d" B  }           
: D# k& v6 V( i' Q  " _; R: v1 n+ k! O6 @/ v
if (document.sform1.checkask.value=="")   h/ t( o7 X7 v0 I) @) {: v5 v- [
  {
* `3 `, x7 {9 K   alert("密码提示问题不能为空");     3 p- ~. l0 W" g# g0 {! w( z
   document.sform1.checkask.focus();     
$ t  l/ y: H0 |% D( `" b9 P, d   return false;  
1 C' E2 j* q( e, B) S  } 1 @! ~4 b# P" L6 u+ Q% P
if (document.sform1.checkans.value=="") 4 J( t: g4 A+ ?* Q, c) p- j( q
  { . T/ }% U6 z+ C+ W( }4 L9 c
   alert("您的密码提示问题答案不能为空"); 7 s# e" [% X' h+ f% I2 k& c0 n
   document.sform1.checkans.focus();     $ [, `: X/ c- b1 s& b* u
   return false;  % G% x; Y* t& k4 H5 T6 k" p- v! E
  }
6 E4 ]& v  u7 e& c% D& D return true;     & e. z: K1 \& F: s% j0 i5 G6 ~3 G$ x, L( v
     : K3 D$ n1 S3 v' `) E6 {+ \
}
! I( [# _% P* |: q& p</script>

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