Board logo

标题: 一个注册表单验证的js [打印本页]

作者: admin    时间: 2008-1-19 23:39     标题: 一个注册表单验证的js

这个脚本对你可能有帮助:0 [; K0 U* k+ w. o$ D: c8 V% m
<script language="javascript">     * ^4 I/ k- N9 m0 c. W& Q
function IsDigit(cCheck)     
% }/ p, @' l3 D {     
- Y2 j  @( G: [8 w0 r0 T- v return (('0'<=cCheck) && (cCheck<='9'));     
; J- Q. {1 P5 \: ~$ E }     1 k8 J, {5 X% u, K3 |* M, ~
     
+ [* A3 z) V. s) hfunction IsAlpha(cCheck)     / Q% F/ p. A% v% C. m; O; f
{     / f) _+ L, i. r
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     0 u) u. h- I: u" c& B, b
}              ( ~) L# `- r7 x) f' J
      ' Q" B7 b. G2 w) I) O8 Z2 G
function IsaNull(cCheck)         
2 f- @# b+ Z- a {         
. o- v7 r& x' M8 L; \ return(cCheck != " ")         # j! Z% p+ t( l- }4 t
}                               1 l0 ~: F" x1 T* T* ]$ [# G( z
      , U8 v( y+ n2 F) P# j3 d/ H4 W
function checkform()     
$ c; G6 R2 @* }; I' [" B{
+ g( j- G" V) J5 G  id = document.sform1.id.value;     4 @+ z( I/ o4 c$ X. }2 W  D
if (id == "")     
0 ]# p+ A! i( C  {     1 C/ ~! @0 g$ @! [" X
  alert("请输入注册名");     
1 G8 q$ h! `+ \* s& M1 M* ~- {  document.sform1.id.focus();     * O9 n( J* r7 c+ |7 g8 Z. Q) n* I
  return false;       L0 q5 m7 Q% G8 Y
  }     
2 l- z' z9 h. {4 j2 O     / P1 ?# U  A3 ?( a- O" U6 \+ d$ a9 m
for (nIndex=0; nIndex<id.length; nIndex++)     
" c+ N9 v& u+ W. S1 E8 V% x4 Z  {     ( @, a1 E4 E: v6 l
  cCheck = id.charAt(nIndex);     % L* Y6 I* B+ i& ~% g( G( t" }0 W
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
+ l$ R# c& Y8 @" |   {     
7 X6 X' V. a# T4 _# Y4 V" f   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     , a1 J8 |6 V+ O  m6 A# `3 q. W. i
   document.sform1.id.focus();     ; U+ x0 e6 q* }& o- P5 \/ V
   return false;     6 M) ~# g+ c& Z+ d" ~; C
   }     ) S) K) a$ g! L6 g2 @% M$ [
  }
6 `* F6 E% v( {. M9 B0 ^  chineseid = document.sform1.chineseid.value;     
/ v. U. I3 M4 K if (chineseid == "")     ' k1 F4 `+ S" K0 O  z/ L' u2 }  m
  {     / ^; f" Z, Q- j
  alert("请输入中文昵称");     
" z- G& X+ T3 u; b6 @: B6 b  document.sform1.chineseid.focus();     / F6 q- N! P+ X1 D
  return false;     + g1 ]8 Y% _2 V& O9 d
  }   
! T' a; ~* c, S6 F$ l5 k  Z+ q password = document.sform1.password.value;     + S/ b5 a$ `$ A) M
if (password == "")     8 c1 J; f7 p( {9 J( C
  {     6 e4 @4 A# ?: R& W( Y
  alert("请输入登陆密码");     + F. _8 k3 R) v+ K2 N# g3 p7 b
  document.sform1.password.focus();     
# P8 I* s2 Z( L  }; q+ E  return false;     
" i1 x, B+ n! f6 q5 @  }
7 q7 c2 g$ D7 h4 f password1 = document.sform1.password1.value;     
4 m7 e. [" y( ]  J' ~& P3 b if (password>password1)       S  }7 G3 d5 C* h; v  i
  {
- H& N2 s9 q2 Z  J) T/ U     alert("重复密码与登陆密码不相同");     # V6 s) r. B: V
  document.sform1.password.focus();
; D% q* r: n- N9 Y                                document.sform1.password1.focus();     
( B/ c2 z) M/ R/ [. M  return false;7 A' n$ L8 g0 n2 w
  }  
8 G. e1 F* Y/ q. w8 p4 D/ xif (password<password1)     
* G3 j1 t2 R  y0 |  {" E, F- ~/ ^; @; G1 G, F7 D
     alert("重复密码与登陆密码不相同");     
) j+ C$ G6 a' B' k# \0 u7 k, i/ z  document.sform1.password.focus(); * s! g2 r* e) r* M# j" v
                                document.sform1.password1.focus();     
& R5 Z. F) T. q  return false;( F; u0 v9 M+ _2 J9 c  r( X
  } 8 o6 q: ^; J) [9 Q
if (document.sform1.email.value == "")     
7 r0 k( H: }# R; H) P+ I4 T2 J4 k* @  {     
4 S  e- V9 U  x  ~& E6 j/ L% S) }  alert("请输入您的E-MAIL地址");     $ p+ H0 u3 U; `% G( b2 H
  document.sform1.email.focus();     , t; ]* r3 S# c" r) a
  return false;     1 \" n3 ~4 T- {' a, N' n2 {0 I
  }     * N7 V7 f% s, O
      7 j; L2 n* E: B" P
email=document.sform1.email.value;      ! g$ a- H+ w/ `9 f
emailerr=0     6 O: E* ~4 }+ Q! B# i
for (i=0; i<email.length; i++)     
( D, p" `6 G2 A, a! ^  {     1 b  V" O$ k' S) E5 ^, g
  if ((email.charAt(i) == "@") & (email.length > 5))     " k2 b: Q2 H  V. x) T
   {     8 e6 R! l* ?& @' L3 g$ ^$ c3 Z* `
     emailerr=emailerr+1     
$ W6 `7 P  d; C   }     $ Z/ s! q# N* ^; r3 i
  }     
! z4 r5 y7 R; ^: _' z if (emailerr != 1)       M9 V; N& f4 K/ N( h. c9 K2 K
  {     
6 E  `: f6 K2 p9 w$ e  alert("请输入正确的E-MAIL地址");     
( z, _$ I! {& L8 r& X* E' d4 V) x  document.sform1.email.focus();     
- v" `" Q' U( s  A2 s  return false;     9 k, ~& u9 l2 F' b) a/ y- G
  }           8 c- A( A  k" E! ~
  ) H4 X8 P" F" }+ O  Y, ^& s
if (document.sform1.checkask.value=="") $ n, [; y& R% ]- x/ [: s. e/ U
  { 0 B) q, a+ u2 |( E6 A6 M
   alert("密码提示问题不能为空");     2 }  e  l) I. e5 k) j% O* i/ b
   document.sform1.checkask.focus();     
  W' m/ r2 P# ~   return false;  
: j# ?; v5 _# Y  }
$ q. U  x5 D6 F& d& V+ e1 L if (document.sform1.checkans.value=="")
- j# g/ n% V" X( D, ~+ h  { 8 Z: _9 w3 a9 v/ U2 n6 s, k
   alert("您的密码提示问题答案不能为空");
- t$ c- s( ]# b+ x! u   document.sform1.checkans.focus();     
# j, @1 Q0 u2 a/ L& \4 s" h% Z" L   return false;  
0 w" Q: {/ Z8 w: J6 P$ |3 C. R6 c  }/ l$ n8 b* a3 g2 b' Z6 r1 ?% q0 k
return true;     
4 Y" ~; S" J+ c5 ]2 ?9 H     8 E# y+ V" c6 C
}
- m! [/ a% l4 ]0 X! L) F% Y</script>




欢迎光临 捌玖网络工作室 (http://89w.org/) Powered by Discuz! 7.2