返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:( _; B3 H% u( M' R3 t$ l
<script language="javascript">     4 u! }) Z- ?' |3 c; K
function IsDigit(cCheck)     
' h0 z. P: j/ T0 V8 W  y( Y {     9 p$ w) E6 S. f" w  R% a+ o
return (('0'<=cCheck) && (cCheck<='9'));     + e+ @9 h" [. @& v& r6 w. P& ~! M
}     
: c- Q  C) m9 D+ n# r* O' Q) m     
* w9 b5 @- x4 v+ P9 o: e, J1 pfunction IsAlpha(cCheck)     " Z5 F* ]% Z9 x! ^) C  K$ d7 I
{     
* M0 m4 |' q' D! u4 \* R return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ( T2 c* _7 Z( X: a8 f
}              & E# J5 C* |( B2 ^2 V
      * p3 b7 ]% l8 F( H4 t- d2 U
function IsaNull(cCheck)          8 c4 Q+ e  \9 N% k5 K  Z
{            L8 G; I3 t5 ?
return(cCheck != " ")         
' v( ~. ~6 P, U3 `' v" B }                               5 J2 R8 n' Q! j1 `; O. O5 h
      
2 v: k3 p# D; Y2 |, c( ?: c8 Hfunction checkform()     7 B( E7 R& G4 y8 p3 ^
{ 9 l$ }" C4 S2 Y8 X4 W4 m5 j
  id = document.sform1.id.value;     6 [6 \9 L" @; K8 B9 ]8 T% q' F
if (id == "")     % P$ c4 `$ X, i. R( e$ K4 X
  {     
) M) m/ m4 f2 M( g0 }* X1 e: J  alert("请输入注册名");     
& y' y# k; D, m. Z6 G  document.sform1.id.focus();     
% Z- ?1 D. P9 T" y- y0 c$ ]  return false;     
2 J& k' e6 c4 s! t: F# c  }     
6 J5 I, u2 B9 J  z, V" S     
9 d; Q+ B: p. L* [7 ]7 V5 `# z7 z for (nIndex=0; nIndex<id.length; nIndex++)     
: ~, M2 T5 m+ G, y3 e; v5 i) Z  {     
; w  H0 r5 ]. }. P# u3 e  cCheck = id.charAt(nIndex);     
8 B* _* ]; X0 P  c  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     + J; F0 O& x- [& y" z5 m* [1 J
   {     ( C, a6 Q8 w7 M9 o4 k
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
9 A* P. c/ Y" A2 P/ ~$ V# Q   document.sform1.id.focus();     
* r+ K3 U# r, x3 N; {7 X   return false;     
) Y* Y  c6 w" G; p2 Z( m" Z$ l   }     
% J" n4 T) W, H2 b  }
; O$ a  s: n- V; J" |$ n  chineseid = document.sform1.chineseid.value;     $ B) y  c# ]. [" `, a0 p2 K9 ~
if (chineseid == "")     $ d6 ~; X& }) ?
  {     
) a/ E; I) v+ C1 V( W  W  alert("请输入中文昵称");     
- b2 r' ~, L+ W# V1 }  document.sform1.chineseid.focus();     
" ~6 B0 q% h  \0 k  return false;     
; n% `, w: [+ ]5 a- x& h: |2 P  }   
' Y/ s( R7 w  G0 C2 C' @ password = document.sform1.password.value;     
% D9 o4 i; X. q( k) Q! c; I if (password == "")     
8 `5 z; k2 a8 t& L- L" b  {     
  Q3 @' w' S4 \' w4 m. h* ^. H5 h  alert("请输入登陆密码");     
( e8 N* B/ C) k$ t6 Y4 [& I9 T; a  document.sform1.password.focus();     - [8 Q: L2 w7 W8 X/ r( ?
  return false;     
3 `: T; K1 K8 w4 B  }
, b1 t  L  H7 Y( m" j3 l# P password1 = document.sform1.password1.value;     6 S0 P2 v* F/ C! K# p& W! L
if (password>password1)     4 `1 O  _3 x  a& @/ [: m
  {
: b( ?- R, {) c     alert("重复密码与登陆密码不相同");     ' R/ S% R; h, e7 N8 }
  document.sform1.password.focus(); . D6 i* D+ }# Q+ g7 C) y' Y
                                document.sform1.password1.focus();     3 _9 `- e$ p/ g  }- `6 I
  return false;
2 h  H, Z% X! O; l! V  }  
9 r3 }2 ]0 N6 |# qif (password<password1)     $ ]& L0 V* J- E" R& s, L' n
  {4 b( A1 Z: w9 ?. ?1 [9 u: C
     alert("重复密码与登陆密码不相同");     
3 [7 b$ \% c7 M: h: \4 ^  document.sform1.password.focus(); & I+ u% @' f4 @# t# t0 ?9 q
                                document.sform1.password1.focus();     * c+ T8 l3 f6 R. }) C! K
  return false;
/ y' {1 Q8 T# D7 j$ O0 o+ K  }
3 K# r  U; ?' ]# q& S if (document.sform1.email.value == "")     
7 u( u4 L! r+ z2 Q" d' x& K3 y% R7 t  {     
6 z6 }+ i2 ]- f  alert("请输入您的E-MAIL地址");     ! Q1 C: b; z( D3 ~- M5 R
  document.sform1.email.focus();     - V4 ~$ j& J& M5 Y. D6 a# j
  return false;     
5 m2 w) H* `# C! a* m  }     ' M2 D+ X* i( l) V8 z8 c& m5 X
      
/ x/ H4 S; j/ h* a3 `& e email=document.sform1.email.value;      
7 Z% E$ U  m% I8 V  |& W! t% I emailerr=0     5 E3 M- D. o+ W! m! C! U) h1 t
for (i=0; i<email.length; i++)     7 _2 H9 D0 X5 J1 U7 f* K4 P
  {     
! J9 o5 E7 s% G2 I  if ((email.charAt(i) == "@") & (email.length > 5))     5 ^" }2 l/ n, B; f$ G5 h6 H
   {     
/ o( w; s: k" m. H  ]     emailerr=emailerr+1     
& D& U4 K( B7 h/ k. ^; x2 j   }     
  V  U# x6 l3 H2 I+ L  }     4 E( Z$ e* V! ?
if (emailerr != 1)     ( W( X5 H6 }0 S/ L' D
  {     1 f# U8 y5 S$ E( C+ ~3 P
  alert("请输入正确的E-MAIL地址");     5 N1 K4 [9 u9 [
  document.sform1.email.focus();     . Y) s: Z+ {0 l* z; y5 ~
  return false;     $ g7 _) u; x" t8 C$ ?. U6 b) s
  }           
% Y+ i4 g6 i  k3 |; \3 `. ]9 M1 h  
/ R, l! \  U* j* b# Z. W7 y2 d if (document.sform1.checkask.value=="") ( Y7 x6 e8 p/ n/ @# x
  { " {" C- @: p: w% \6 B0 E1 v' c& |. u
   alert("密码提示问题不能为空");     
0 c5 M1 f5 l1 q( Y; ~, A7 }   document.sform1.checkask.focus();     
. p( J. J( a. \+ e3 b3 k   return false;  . R, P* Y9 e5 v
  }
5 E2 Y) Y/ q" F9 L if (document.sform1.checkans.value=="")
/ t9 f6 S; q4 F  { 5 |1 ]9 \5 A! t. ^  _6 i- ?; q4 S
   alert("您的密码提示问题答案不能为空");
6 l4 l7 u, C. [' J' e2 R; h& V   document.sform1.checkans.focus();     
- Q, w5 G6 ]: ^1 A4 @   return false;  
( o5 i0 w6 T; q  y' O) o  }
+ D$ |" K, |) u8 m1 n return true;     
- w+ f+ A; w; _6 p8 ^     
& n2 J: D' e" j0 S% w}
/ Y4 v5 Z8 t8 P- [& w# L</script>

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