返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:5 n& n& V8 x1 \  y- B* s$ F
<script language="javascript">     ) h2 U2 M% G( M0 P. t% n
function IsDigit(cCheck)     
" a1 E5 t7 s7 |! }! k {     3 R- e- k8 y7 S9 q4 G9 U2 R
return (('0'<=cCheck) && (cCheck<='9'));     
0 R" t" B: X  i' i0 f& A( Q4 K }     - r  E7 [3 b9 ]0 N% ^- }6 m
     ( C' @- e+ g+ x4 |
function IsAlpha(cCheck)     ! C# O, `' K; f) y# M7 W! b# }
{     
. J' Z1 I5 W: p4 G, j& _, _ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     / ~2 Y5 ?7 |/ o, a( e9 D
}              2 K7 P* h5 x& S( u1 J
      
: M5 W. F/ o7 v% v$ R) ofunction IsaNull(cCheck)         
* R7 B! k: m& O1 @ {          1 `: o6 n4 I: f0 Y- S  i
return(cCheck != " ")         . z+ z% P% h: A, e6 L- H' P5 u
}                               % w% I7 {  B$ v4 b$ _7 s
      * X; f% z0 I3 o3 }' y
function checkform()     . N8 x: K$ r3 H* J! }0 l
{ + _& r9 g; F* u8 y3 d: |
  id = document.sform1.id.value;     . x  {! w% Y* y8 q: c6 W
if (id == "")     
4 Z* w4 u. G" O, E) r  {     ) m7 I' O; Q. a6 f4 I% K- P6 M
  alert("请输入注册名");     
) P* u1 u, u; q0 G3 p% Y6 `  document.sform1.id.focus();     
4 y/ J9 B9 `0 j' _  return false;     
: Y: ?% B. @1 [/ O  }     7 [, j5 C) I( R
     
5 U) [# j9 z* v% y. X. M' s for (nIndex=0; nIndex<id.length; nIndex++)     & Z- c- f/ w# ?4 L7 A8 @! j
  {     
# K6 E: c! m' {  cCheck = id.charAt(nIndex);     2 o, Q8 o/ h, g* g
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
, D+ U, c2 l2 J; O6 i* {   {     ( F, U4 _- P9 F( [
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
/ a0 T/ `) ?: w% y, Y! p   document.sform1.id.focus();     
# J: L6 L+ U. L& L" N   return false;     
2 N5 V. ]. Z, x& D' r   }     0 {6 Z1 p) w) x2 g- @) g
  }
* Z0 D( o+ k3 y( L8 Z  chineseid = document.sform1.chineseid.value;     7 R+ T, c7 u% ?$ V% c0 ~' p2 M
if (chineseid == "")     
/ D8 _* E  `8 M% @! \' }: Y4 u- a  {     
$ }. s' n. t, I8 C# J  alert("请输入中文昵称");     
$ I' x$ C/ n- ?$ }) ^6 s; E  document.sform1.chineseid.focus();     $ ^9 H: y* t, \- R2 {+ M  f
  return false;     
; D& D  h' i9 ~3 I( X3 G  }      }/ c+ T; Y( ?+ d4 ^& s, w
password = document.sform1.password.value;     9 P% u' Y8 h: p" Z' y
if (password == "")     $ x7 U3 j3 `0 j' r8 d
  {     : N3 O( v. Y1 |! H
  alert("请输入登陆密码");     8 n$ C+ M9 z: w5 B
  document.sform1.password.focus();     
0 ~6 Z4 j3 s  A+ j  F# P  return false;     
# u0 r7 ]8 D$ f2 K1 u1 N  }
  {0 h/ ^5 [& ]" ^ password1 = document.sform1.password1.value;     $ [) B5 S/ ~; c$ O- n# r/ @
if (password>password1)     
; O0 p1 M; z) B( l  {0 W8 F1 J2 f$ G* d* u
     alert("重复密码与登陆密码不相同");     
9 {/ d6 T, x2 n( s3 H  document.sform1.password.focus(); ; ?4 }. T1 W. N% Y8 ^/ E
                                document.sform1.password1.focus();     4 j0 A9 y) j9 g  c% J! q$ h
  return false;
- E0 O4 e; |7 h5 L  }  / e( a7 [6 Q6 M, ^, k8 U8 Q0 M
if (password<password1)     9 s# J4 i! g- e5 d7 y
  {
; g: B& J3 w" D, g2 w     alert("重复密码与登陆密码不相同");     
) H6 ~( p2 s7 s; f# v" V9 @; n  document.sform1.password.focus(); 1 s/ R" u# O- g5 x0 N
                                document.sform1.password1.focus();     
  O7 h+ \! x9 s; Z1 y  return false;; n9 L! `6 g2 t9 Z; F
  }
6 A) m, o2 D  \  t2 v2 s5 h; _$ p if (document.sform1.email.value == "")     % H' n  z7 X' W' y& {6 k
  {     
4 V  B& c8 R2 J7 x2 J$ r  alert("请输入您的E-MAIL地址");     $ P. w% I& O9 {& `% i: k' d9 c
  document.sform1.email.focus();     
4 s( _/ d" @7 s5 {  return false;     
$ t8 w  \3 x  P2 K# T( _3 m$ z  }       R, ?- `( G& v. z1 L  Q
      
' i) _3 e' o. V6 s email=document.sform1.email.value;      : Z( U# Q" `7 |+ B. T! v
emailerr=0     
" Y+ N5 X& K5 ]2 p' d% B* z for (i=0; i<email.length; i++)     ' F! ?( N" c. B" L1 n. b- R
  {     
  x, @, v+ O: R/ j: O$ b  if ((email.charAt(i) == "@") & (email.length > 5))     
5 X( k* O- G, e   {     
5 F( A+ W3 m# z     emailerr=emailerr+1     : {& ^% f3 K! L, M# j, S. C
   }     7 a7 _/ e( ]& _1 q
  }     
& s( \3 f/ h2 k% x if (emailerr != 1)     
9 ?/ |0 x% x7 o8 h8 h/ u  {     0 _0 n, I4 O  x
  alert("请输入正确的E-MAIL地址");     . W! o( X3 p7 H7 h
  document.sform1.email.focus();     
: R1 y7 d* m3 s. }' ?5 ^  return false;     
2 r) T: s. B- m2 }3 H. R  }           7 ^% Z. J5 \0 n3 R2 V* k; g
  
* S2 Y- u3 F; R* c( q& u! i! z$ B if (document.sform1.checkask.value=="")
! [. f  B7 M1 ?$ }7 R& H  A  { % o; H4 `, F; B3 _1 m8 F
   alert("密码提示问题不能为空");     $ y+ T4 M$ i7 h( E# P
   document.sform1.checkask.focus();     
; N8 j1 l+ X" h5 e   return false;  + k! k/ I/ i; r' G" C" g- c4 p
  }
3 b+ b% ^2 L! d( v& [! L if (document.sform1.checkans.value=="") 0 h7 V. L. K6 S. R' u
  {
0 x# `2 i" E6 t9 r$ N9 W/ |' x   alert("您的密码提示问题答案不能为空");
3 \+ h0 e$ O- b1 s: q7 q   document.sform1.checkans.focus();     ( S, a; d/ W, b8 ~+ ^
   return false;  3 [: z' e* f6 q0 f! l1 v. b+ r
  }- B, V+ R+ p! r* t# T
return true;     2 q7 N! k1 w+ Y+ l0 S% W6 a( E
     
& M, u' p6 S0 Z  C}
9 d3 Q. D9 X3 `7 j: V</script>

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