返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
2 n& L# [' Q* J+ n<script language="javascript">     
5 R4 H- |* y6 k/ [( G  tfunction IsDigit(cCheck)     & n9 d$ g) U: @% q( n
{     
5 c9 O8 @3 B( t& {/ G return (('0'<=cCheck) && (cCheck<='9'));     
1 J/ P8 ^% ?% z$ E }     
0 ^' H  [/ f; G: ]3 C4 T     6 x' o* Z5 S; w8 `) h& B
function IsAlpha(cCheck)     
! a" u2 e* Z" B8 n2 T" X {     
9 C5 E; f6 C& H' @# e: ?# z- z return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
, W# f: R8 J% V) K }              
6 ~* b* g/ f$ ]8 k      
: |' |& K0 T, @2 @2 v: Xfunction IsaNull(cCheck)          $ Y4 v. D1 K8 }7 A; t( J
{         
! N6 \1 m# P* o' [; L return(cCheck != " ")         
6 l2 J$ _3 F5 n, Q0 t2 \. @ }                              
5 u% ?' N% r+ U- T1 [8 ?      
% Y7 W3 v6 n: j/ l( N0 p3 a  {& d. ofunction checkform()     ; k( o  x2 j$ T% Y
{ ) L& Q: q. ~- Y, \) y( o/ e
  id = document.sform1.id.value;     2 A2 ]5 t+ J+ X+ c
if (id == "")     
" ~; H7 B) J+ _( Z; t; t4 u% R  {     
. R. p' F2 p0 w' v' g+ w; a  alert("请输入注册名");     4 r; a  [$ w  X. @
  document.sform1.id.focus();     
) O) u8 y0 o3 A8 k. P  return false;     ; H( B0 p+ ?# @6 x5 C
  }     . I3 c: Z% O- `) U- H+ E
     # {* X3 @# V, \3 w# g
for (nIndex=0; nIndex<id.length; nIndex++)     
0 T1 a9 q: z& t4 W! Z  {       U9 p" n# R. @& k8 `
  cCheck = id.charAt(nIndex);     
1 T& i+ V  C. P+ r9 L. n  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     2 |- v/ r, d; i/ Y- J
   {     
* l+ V. z5 b" ~# q4 a   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     " Z% G( L: w+ ^  P8 [& G: ^8 f, i
   document.sform1.id.focus();     
8 W; r9 `" E+ ~8 q$ Y5 O/ i   return false;       H4 t$ ?; A) y) z, M& L
   }     2 S  x4 [5 Q% H. i4 b
  }
# t. X2 p: P. `, a" Z: I% Y  chineseid = document.sform1.chineseid.value;     
5 P3 U3 n+ o/ C0 f if (chineseid == "")     
  n1 K. c, ?9 w4 g) M' g' O  {     
! e( S/ F; h$ D+ A! c/ ]0 s  alert("请输入中文昵称");     ( y4 _- U: i( B1 b2 l" s4 M( u' G
  document.sform1.chineseid.focus();     # D7 [! G) I9 @
  return false;     3 w9 N( e4 p! x9 i9 d# s1 Y; Z, x
  }   
' n3 s' Z7 g* }0 c: ?' `; P- z password = document.sform1.password.value;     
+ u2 R9 T" u, g) A if (password == "")     0 o: ~1 M3 l. D) u
  {     
' r8 W  E* L  @$ X! ?  alert("请输入登陆密码");     
# B% @! \# [3 k. ]# ~( q, m! M  document.sform1.password.focus();     5 U; {9 B$ \$ R, G& r
  return false;     
2 F" Y. J0 ^" ]3 c  ]5 P  }
& R$ Y7 J5 h% L) a password1 = document.sform1.password1.value;     6 x% K0 K! h/ {
if (password>password1)     ; _% a/ R0 a7 `: |/ x) D- |
  {7 e, U/ m( s* u( J% W
     alert("重复密码与登陆密码不相同");     # G& \4 o) q& D" d# w4 n
  document.sform1.password.focus();
+ a! c9 Q' C' M4 y8 A3 \4 S                                document.sform1.password1.focus();     
9 ~  M0 _) c/ \; _  return false;
. y1 ^! Q( L" e/ A  }  - @0 ]& r$ T3 ?# s, u
if (password<password1)     ; w( B! q6 {2 S0 x2 l% ?3 H
  {
7 J$ A/ T, w. O8 w4 ~     alert("重复密码与登陆密码不相同");     3 s  |% m6 M. z0 x& x! V- g
  document.sform1.password.focus(); 0 x  R* {! B" e5 j9 G/ p) q+ P* _
                                document.sform1.password1.focus();     
* I6 }7 ?( T. l* n  return false;
4 a- M2 J2 j0 L' d' e* F. v  x  }
4 {  V/ Z3 S8 X9 W if (document.sform1.email.value == "")     
% x8 A) ]1 N+ v' q  {     
. [2 Q8 A  l( B5 V, A2 O: ]) M' f  alert("请输入您的E-MAIL地址");     " A* W* n! g  |* {% }
  document.sform1.email.focus();     
& f4 I" T0 J  W7 b% t  return false;     * w1 t% l5 G- x( H) c. Q
  }     - Y( r+ P2 s6 c' ^# x, x
      
% g, g9 d, P2 v. L- I email=document.sform1.email.value;      6 m& d/ Y; t3 A& e
emailerr=0     2 z0 f  M/ l# M9 z4 B
for (i=0; i<email.length; i++)     
% l8 [& D8 I. f7 S7 j- @1 m  {     
) h& P$ P$ L  r+ f  if ((email.charAt(i) == "@") & (email.length > 5))     : q7 r4 c1 Q$ g* Q
   {     & c( }, |  O! ?; T, G
     emailerr=emailerr+1     : }7 B  F$ C& ?  U6 }
   }     & X# l" w) X: z/ N
  }     
+ H" p2 E, c4 y if (emailerr != 1)     3 q6 q6 G% ]9 ]& Y# [" [' H8 c$ h
  {     + [+ Y1 ?0 `7 s0 ?/ j
  alert("请输入正确的E-MAIL地址");     
( A4 C( K' [8 @# h  document.sform1.email.focus();     ) E' m# c) d/ Y- ^3 v* y/ F
  return false;     + Z$ O3 @  A4 l1 L: A
  }           
+ _! j5 I! [9 _% ?; P2 J  
, T0 n; a( @5 l  L0 C if (document.sform1.checkask.value=="") 6 m) t3 K0 p5 y: c7 y) K
  { 1 Y* q! _/ n  n' M
   alert("密码提示问题不能为空");     $ l7 Z6 B3 y  ^  j$ g' I
   document.sform1.checkask.focus();     ) a% W2 i4 s1 X" n: Q$ N4 }6 m
   return false;  
2 v6 f4 j+ P" J; J0 l% i  } . A. I- L2 X8 |; I6 G
if (document.sform1.checkans.value=="")
; {# Y3 N0 @, i7 P  { 3 ^: u8 O- s9 o2 q8 U6 L
   alert("您的密码提示问题答案不能为空"); $ q' m& X2 p( Y
   document.sform1.checkans.focus();     
# b/ p% c/ S  M8 }, b3 R0 W   return false;  : k4 z$ @4 V1 P# {
  }; K6 k5 D# ^7 N1 N6 ?. ?6 g/ E2 w1 x
return true;     ' F* {* Q% w( r/ i- ^
     
1 `# l; c) U/ o) V6 p: ]) `" n} # {7 ^- a0 y. X& R# h) ?6 r
</script>

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