返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:$ V" X3 S, n" L9 O4 |; @& @1 i
<script language="javascript">     ! |/ |& ]+ E, Z( N+ @) E8 f# q: ^& c
function IsDigit(cCheck)     $ N1 R+ m! r0 H/ f
{     9 e7 L3 j. o% a
return (('0'<=cCheck) && (cCheck<='9'));     
3 b0 i; F# j* O8 @ }     
! N, O" G) Q; M+ A  H8 l     
4 g- D/ ?: G# a8 ?. g( {function IsAlpha(cCheck)     
. a5 P' Q8 D) D$ t3 U {     
* m1 h* C& \- N* a: N+ D( r return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
2 l! H0 f$ \5 E+ F3 G5 a }              
$ L/ A& s  t/ P) w      ; j4 d) l+ {2 N/ \
function IsaNull(cCheck)          4 g" r1 l8 @3 ]; T: ?
{         
1 e$ p' }, i$ j7 W& i return(cCheck != " ")         + B9 G7 U2 [, @- e/ J" [6 K2 e  F
}                               1 I4 S% [& s: j8 F
      ) _' s  ^' H# H( ~5 K% e  w
function checkform()     8 V" N" _" F8 S( L9 j' n
{
. n: C8 n5 h+ l6 e  id = document.sform1.id.value;     
; r, [8 L' M1 ]0 O  s if (id == "")     
$ o5 G7 ^1 @/ S' n* B: s! N" x  {     ' H* r2 W5 h* l* v  l' ^5 N
  alert("请输入注册名");     
, |8 _( ^! [9 X; i' ]  document.sform1.id.focus();     + ~$ H/ l' z! W8 a" D4 X
  return false;     
' V7 h# I4 I9 O+ U8 z- b8 U  }     
) \' {( a- l$ B/ O' j( s0 h3 @     
3 A; @/ P# j1 n0 m, C for (nIndex=0; nIndex<id.length; nIndex++)     
0 j1 o( \9 J% n  {     / P  ^0 s9 i! p$ k* Z0 j5 F- k
  cCheck = id.charAt(nIndex);     
1 X; x, V0 d" b( t# @5 o. h  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
- t. D. d1 V$ @3 ?) J# {   {     
1 z7 Z4 P  A' b/ S. |   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ; g- j9 y3 ^) h, N
   document.sform1.id.focus();     
0 w; G9 o8 w) B( ^2 f& z) a   return false;     
  D, b. a1 s8 b8 P   }     
5 W; |& _$ i; c% e% v5 U) h  } . g4 p( b8 H" q: v& F( Z
  chineseid = document.sform1.chineseid.value;     
) `: S3 Y0 X: A  G if (chineseid == "")     
6 g1 F6 p( }; ~/ {0 D( F  {     
' u5 f" G8 L5 L; I, ?- R  alert("请输入中文昵称");     
$ B- q5 w5 f: n% T2 O  document.sform1.chineseid.focus();     6 a/ [: H. B& }! w" c
  return false;     
& Z& V- @1 e8 @8 W$ ]% u- s  }   
  J" {; K. S8 G password = document.sform1.password.value;     6 V/ C( a3 R) y6 q3 g
if (password == "")     
6 V3 z9 l. ]9 {( q$ Q% w  {     " w* X* U- k& E$ S- D% q
  alert("请输入登陆密码");     
7 [$ u* P' n3 O$ a7 J  document.sform1.password.focus();     
7 V  |( @8 y" [- `: m1 I/ ?  return false;     
! @+ I4 g+ C6 n% M' u$ }* ^/ |2 J' {5 n  } 2 e" Q. o. Y- f2 U+ k: x, W3 \3 W) w+ T& P
password1 = document.sform1.password1.value;     
: M2 t! F% J9 X1 B0 c0 v if (password>password1)     
+ g& E: ^: P5 M9 ^: k# C4 A' C  {' }4 S2 ]6 H, @+ Y7 l) v  @& h1 u
     alert("重复密码与登陆密码不相同");     3 u, D5 H8 [2 B- }' C
  document.sform1.password.focus();
) j  K' I" f; V% N2 K                                document.sform1.password1.focus();     
6 u5 _& g# V1 M/ H1 [) G  return false;
5 v; ^6 ~: T1 B7 }3 C+ Q( p5 y( G  }  ; ~1 O0 A  k" R* q- L
if (password<password1)     ) q2 l, O. N' r# [* S* g6 H4 V
  {* I- d* C3 L/ n1 a1 e9 c9 I
     alert("重复密码与登陆密码不相同");     
( X- y/ @; Z2 T8 V  document.sform1.password.focus(); 1 [6 s6 i- c9 n7 G+ R% {+ z
                                document.sform1.password1.focus();     
6 V+ q; k# z. U9 t# a  return false;+ V  S4 x6 u& J: e7 `
  } 3 X8 V/ e) b  n  y/ V, n. A
if (document.sform1.email.value == "")     2 J: l$ W7 a5 Z  A( v, o
  {     
3 B" |" [" e: Q/ ?! N$ b9 s  alert("请输入您的E-MAIL地址");     
; s) j) w* o5 M" K' n) q  document.sform1.email.focus();     
0 z$ O# [3 ^- a* n" e  return false;     + M0 {5 d3 `: O$ H
  }     1 o, _; d1 u* S
      
" ~* S1 J1 J+ w( L email=document.sform1.email.value;      ! {( j/ `  r: W" i: o8 n" t7 n+ h7 f
emailerr=0     
/ _% a4 I$ m' u, T2 G0 ]. Y for (i=0; i<email.length; i++)     
4 g" c( ^; H6 o  {     
! F5 ?4 U$ e% i* m  if ((email.charAt(i) == "@") & (email.length > 5))     5 Q% F9 a( d2 z; C  X  z
   {     ) e) `" m, ?" Y" Z4 P$ r
     emailerr=emailerr+1     
" j$ q# @8 _% B8 ?1 S" w   }     1 t/ }7 W3 U$ P, n
  }     
" a; p- n- W4 ^2 W: o  h8 F if (emailerr != 1)     , [0 R7 `! n0 p4 ~
  {     
5 g& w: S8 S- @+ J1 E( N  alert("请输入正确的E-MAIL地址");     $ T+ L0 s  I/ `7 `' \
  document.sform1.email.focus();     # D% v7 C: T" t4 \9 H# s# N
  return false;       K1 D8 H$ I' b4 B/ K
  }           
. z/ r7 s6 _* Z" W1 U& y. _  
7 K9 i) m9 F4 v( u! n6 P if (document.sform1.checkask.value=="")
+ v% e4 @4 y- v; ?9 Q8 `  { ( y! N' N. G0 Y+ F
   alert("密码提示问题不能为空");     + r8 U6 R1 G& G
   document.sform1.checkask.focus();     4 [' _) U; O( v( b/ G: @1 b
   return false;  
) W% ^0 r8 ]0 N2 L7 X& @$ a( v  } + b( c  Y9 E! V. G
if (document.sform1.checkans.value=="")
0 u1 q- m2 Z; ]/ g) ~) _  { ' m0 l% ]; i, ^+ N
   alert("您的密码提示问题答案不能为空");
0 h# r/ v# \& G" x0 U   document.sform1.checkans.focus();     
! h  b: F5 f) e/ s* q   return false;  
3 \% l+ v  ~8 `: }# s) B  }1 N& `8 o, q4 ?9 r
return true;     # p% O, U; j/ i# [1 b3 ]
     
" @) X3 s7 i9 C}
7 `) y5 W, k2 }5 y8 C! `! L* h7 y2 C</script>

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