返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
: j0 o! U4 y8 j, b<script language="javascript">     6 v+ J; n/ {! r1 \! n$ v
function IsDigit(cCheck)     
! ^/ w3 V6 V" u, {7 m' c4 v% o8 R {     
9 F( }# M- _0 S- k return (('0'<=cCheck) && (cCheck<='9'));     
5 Y+ S& y( }* [) ~$ D" Q }     / T3 w/ [$ ?: S6 X. Y8 {
     
  I* [& J' C* x& i: g* ?" P. Ifunction IsAlpha(cCheck)     
; `7 a  G( ]% `% Q3 m" z {     - B' r/ q2 X7 m( I
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ' b7 H3 p8 k' y) x: n' m# M
}              + p8 S2 V8 a0 W8 \! n
      8 E! m! @9 H  u3 p  H! `
function IsaNull(cCheck)         
3 _4 b1 R  F) ? {          / D: x3 I  F' z) @( f
return(cCheck != " ")         & C$ x" [2 Q5 ~3 ]( T, x
}                               ! j% @- e$ M- K* C9 k
      
" b2 s/ {" `% afunction checkform()     
( N8 g( y* R8 N( [: r8 y* t" f: f{ 1 E+ y6 i2 R' S1 p
  id = document.sform1.id.value;     $ e5 T2 `- T* m& r2 ^! X+ @4 i
if (id == "")     
' e% j9 u2 B% ]  {     
% L. `9 {8 R+ A# @/ m8 `  alert("请输入注册名");     ( F: x1 i% I: A! B, M
  document.sform1.id.focus();     ) Z: D$ Q1 U3 |  C  _4 E
  return false;       W$ @# F& I8 [$ L  n$ a
  }     
' {4 }7 g3 h: K5 j8 {/ Q9 Y     / X2 h( J9 C; w3 A
for (nIndex=0; nIndex<id.length; nIndex++)     
: q: y, W- R% a% d  {     
/ s0 g8 S0 J0 E* S+ e3 `+ h1 H1 L  cCheck = id.charAt(nIndex);     2 d% F  A* G; G4 M8 @
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     6 f1 N; u5 w) P2 ~% I, O. @3 V
   {     
! n9 G7 {2 j# A# S, K4 O4 t3 x, w7 e   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
, N* z: l% d; I# }4 a   document.sform1.id.focus();     
1 U2 ?$ M) t4 Y0 s! s! J6 F   return false;     ! Y  s7 i$ D/ R. h5 S3 ^, Z9 {1 a7 r
   }     
" G7 D1 _9 F- E* q4 Q0 s9 {  }
' b# W9 E' g# y- b  chineseid = document.sform1.chineseid.value;     . Z+ e0 g! w4 |# V4 M* q
if (chineseid == "")     $ K7 f$ z) w: a" I0 {( s
  {     / x* u  z+ p8 }
  alert("请输入中文昵称");     
9 c2 G! M. Y0 ?9 t  document.sform1.chineseid.focus();     1 ~" |: l, e5 P+ g" H' d. v' k4 O
  return false;     
* ~# B. ]& Q! o0 U- X  }   
$ V* D9 z# _  `8 S" p; f; M password = document.sform1.password.value;     
8 C4 J* g" M+ @ if (password == "")     
+ F5 G& W) @' ^% S2 k! B- K+ j) x4 y8 \( \  {     
& J# f$ ?+ N) j* I  alert("请输入登陆密码");     
! e& `) Z7 E( v. a( T  document.sform1.password.focus();     & n6 H( N6 \4 g9 z
  return false;     $ Q! D$ V) Y+ W1 e
  }
1 T3 \; c6 @! u6 d% s2 G password1 = document.sform1.password1.value;     
, {4 f- |3 s8 p: m9 q: z$ |( K if (password>password1)     1 B: [4 v; R% D
  {
5 S  w9 p; y4 S) _/ }     alert("重复密码与登陆密码不相同");     
  c% i4 H# [+ F! G& o  document.sform1.password.focus(); 4 U$ P: l/ F( |( q# W6 R
                                document.sform1.password1.focus();     , |7 b& Z+ r* o  _' X0 Q2 y6 G% w
  return false;
) S2 r5 C# c' C9 S% q* g  }  
. Q  |5 j, g# o. b4 Iif (password<password1)     1 S6 N) ?! r" T* y6 W
  {; T/ P7 \! g: J
     alert("重复密码与登陆密码不相同");     
7 q& X. ~: C" O; P! V8 s( u9 P  document.sform1.password.focus();
; ]9 |! p) |& K4 O  b3 V* ]" ^                                document.sform1.password1.focus();     
: D1 J& v  K: |9 F6 i* @7 _& b  return false;3 l; o+ r: i6 K8 _
  }
0 y% Z- ^: y6 R: i- W: S* C if (document.sform1.email.value == "")     ( B/ e8 B; O) |
  {     2 Y1 J# V$ V2 w2 Q- q
  alert("请输入您的E-MAIL地址");     ( X; Q: `% F- u! n  D# n
  document.sform1.email.focus();     
8 ]$ z" R8 x! D6 y: c8 N  return false;     8 _5 |( h& N9 T4 Y8 G8 g; g
  }     ; e# E3 O4 {3 ^9 |0 W
      
7 x# i0 O  H& b2 ?5 ?5 R, x email=document.sform1.email.value;      2 N3 e; l3 @& A; C4 W+ @8 e2 L: r
emailerr=0     ) u" |9 g2 M) S: w: l0 A. V
for (i=0; i<email.length; i++)     
9 Z* Q% z7 |/ W3 g9 N2 O/ Z' T  {     
/ }+ k7 c+ d$ t3 b  A' x/ c( R  if ((email.charAt(i) == "@") & (email.length > 5))     
" m0 \3 A% y- q   {     
3 Y2 L- v0 C3 z/ j3 C. H! {     emailerr=emailerr+1       L) t% q1 p3 S3 o+ S% @; I2 \8 g
   }     7 x0 s2 I- {0 c/ s7 E
  }     2 P3 R6 O. f) ?' _% n7 d
if (emailerr != 1)     4 a. b  G. J! ?
  {     
( g8 M5 s4 I% r  alert("请输入正确的E-MAIL地址");     
% U0 k$ d3 r* Z9 z' Q( X  document.sform1.email.focus();     
" ~% B% e7 }; H: _  return false;     : i- t7 @4 y. r6 B& x+ j
  }           
9 c8 J  n+ N3 [# A3 s. a  - g% a. C9 |/ O; a
if (document.sform1.checkask.value=="") 3 \, d3 N; B# f1 D8 ^5 F
  {
; G7 K6 t) \& d6 m: U* y: t   alert("密码提示问题不能为空");     
4 u( W5 L9 f- Y$ c' l# Y" _. n% Z   document.sform1.checkask.focus();     
( m9 w/ x; k. H& P$ g- F, r3 o   return false;  
* e/ s5 r& x) C. E. Q2 S6 M  } 6 n( k+ Z- c$ j; o0 f$ s! q
if (document.sform1.checkans.value=="") # k* r* v$ i4 M( i9 K2 x; H9 l
  { $ k: f/ g, l1 r* O! V" b
   alert("您的密码提示问题答案不能为空");
' h  Y" S% p3 F3 a" ?" q   document.sform1.checkans.focus();     2 ^( s" ~/ l8 b* Z- f, a
   return false;  $ g5 S1 ^& W/ N8 b* W' }
  }
" ~- L  g1 j! s: h; l return true;     
5 Z9 R. J' C( n& J% L: N3 `     
" x2 A+ a# P# Y, [3 M# r}
3 r4 Y1 ^: {, t& X</script>

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