返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:4 i  x4 \+ v( T/ r1 P, s0 J
<script language="javascript">     : U; x! j! Y) ?1 F$ K- X8 s
function IsDigit(cCheck)     
" p8 m4 w2 w  O; i1 p! o2 N {     ' o2 U  U8 o# e5 g( X3 x
return (('0'<=cCheck) && (cCheck<='9'));     
% c9 m; G) n8 Y8 O0 L8 _% f3 v# y1 c }     . n8 Z$ ~' M6 c
     " ]1 r4 S" G% c% Q. S
function IsAlpha(cCheck)     8 Y; m# Y1 a0 l, ?. v
{     
* h% {7 R. ^1 W) o return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
  u4 V6 a3 ~  }/ S4 I* ^ }              . N7 D) t' b1 _% {
      
  F5 e3 y' G3 K$ @" t% g( Nfunction IsaNull(cCheck)         
; _" p" k  Y; v' U& d" Y$ g {          7 V. A4 j8 Q3 M6 a- D; q
return(cCheck != " ")         
1 v) @/ ]1 R- Z5 Y9 [+ L5 h }                              
3 {( [, u3 v' B4 t      
. Z4 l& \3 X' F: z& G# [+ y* U; Qfunction checkform()     
1 s& i6 y& Y, s+ r& f/ W{
5 i0 {7 d' n6 i3 F  id = document.sform1.id.value;     
1 z, f1 H+ F3 y1 V+ m% m( c if (id == "")     
3 {" {0 ]2 y, g2 b# t# b/ T0 M  {     ( Z/ u5 S! \6 Z
  alert("请输入注册名");     
. x  R8 T8 t% f$ @6 q  document.sform1.id.focus();     
$ H" o( h0 K7 G# ]9 b- [& B, [0 U  t  return false;     
" H- a" L) ~+ S% R0 a' O& e  }     ; V# T& n0 r, i5 ~' O" e
     
! y0 y4 }- u( G$ R5 b+ J for (nIndex=0; nIndex<id.length; nIndex++)     + s: c) \  j' L4 z% Z
  {     
5 Q! y2 T- B( e/ ?& y- F  cCheck = id.charAt(nIndex);     * b1 r# i+ L4 k: l8 n5 v
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     " t# t" o8 p" H0 F! K" Q: q
   {     
6 O, Z+ A9 g( {* q) H1 f   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     6 ?# s6 B6 c# i* V
   document.sform1.id.focus();     : A( O+ I% _; D& O+ e8 U% ]
   return false;     
" k% y& v/ C$ t1 I) G5 `' O   }     
+ q5 ~% Z- z" a  R' n  } ( a) w! ^6 c3 W- \5 g/ s6 x5 k; U
  chineseid = document.sform1.chineseid.value;     , h$ |+ y( E/ L
if (chineseid == "")     4 n* r, L9 f1 d/ _( x0 V7 z! T
  {     5 a! H# f* ?; `. N
  alert("请输入中文昵称");     : X' C! R1 @# [$ B
  document.sform1.chineseid.focus();     
5 Z* c, t% v* ^+ H: r  return false;     
, L9 N7 n6 O8 u! H  S) p! f2 t+ K  }    5 A- `& B) h2 t- A: @5 r
password = document.sform1.password.value;     7 T- I9 H7 r, Q$ M! I' h
if (password == "")       _; s/ F  `+ m, d! ?! p) m
  {       ?' h# x8 Z  f5 P
  alert("请输入登陆密码");     $ q) k) Z* E% m4 d' n1 J  }2 q
  document.sform1.password.focus();     
. I0 w- P1 H) ~# a  return false;     
+ ?8 q* C7 r# ~& {  } . y- H( f+ c$ B0 r4 d: t% c
password1 = document.sform1.password1.value;     
  D- x: }9 A/ |+ P2 ~ if (password>password1)     ) O- E# ^' S0 V: A
  {
) h+ f, w7 J2 w" E" C- Y. e     alert("重复密码与登陆密码不相同");     + t  r4 ~! {% U- x% [6 V* @
  document.sform1.password.focus();
' p# `  ~. Y" g2 ~+ i                                document.sform1.password1.focus();     
5 `" `! e; C+ ^8 K5 M  return false;! G+ F* E/ G1 A5 Y  Y! o
  }  
3 F: \, ^" G+ W% [; m' p& \if (password<password1)     
1 Z# F# Y+ d6 N9 z- D% S  {/ w* n/ _$ s% P
     alert("重复密码与登陆密码不相同");     
8 G; g0 u: q; t0 V& O4 p) B  document.sform1.password.focus();
* X2 i! g" w. Q! H                                document.sform1.password1.focus();     
+ l3 @  E! v( ^8 s  return false;2 J  W" C* G. O4 S
  } " F7 @" z" u3 }9 J: l
if (document.sform1.email.value == "")     
; p3 c, C* a* T" _  ?7 M/ b  {     ( A2 |. }+ t, b1 ^) H, L4 Z0 e
  alert("请输入您的E-MAIL地址");     ' k2 H9 I1 F; {- |
  document.sform1.email.focus();     % y- ?  F( ~! j# N- \
  return false;     4 W$ V" f; `+ j5 Z9 y+ E6 z
  }     ' A+ u. V( F6 S4 O' ]& I
      
( |& \0 H8 m. K& t# s email=document.sform1.email.value;      2 i( m7 E5 ]& T7 y. i
emailerr=0     5 I1 l& F& v6 S' R! d& h
for (i=0; i<email.length; i++)     
& I2 [. S: H" ?+ W; w+ z  {     
3 S3 A) F: z! l: @( }; W  if ((email.charAt(i) == "@") & (email.length > 5))       f1 M5 \$ K9 t1 n+ H$ s
   {     
" X/ F- q' J6 {( l2 I9 e     emailerr=emailerr+1     
1 ]/ ~* u7 s4 a6 ?( Q6 Y   }     . t7 _8 T" W+ s; r! w# L/ F. V
  }     ) k! S; r& @7 i6 y* H0 D4 Z
if (emailerr != 1)     
' {% N: z) E, z- \  {     6 a: y+ E# A( \) w6 ]0 [
  alert("请输入正确的E-MAIL地址");     
1 ?* g* Z' N( r1 w! }  b/ U  document.sform1.email.focus();     
3 y# S$ a9 D& M6 V7 E  return false;     9 i; m, P& E; t
  }           
( n7 K' l8 C* n  , I# [& U5 j% c$ Y& P, \
if (document.sform1.checkask.value=="") 2 S6 X, k0 w4 M0 Y
  {
+ Z: V" [' C' H5 H' \/ C+ o5 F   alert("密码提示问题不能为空");     + t, b( \2 T' k% O' }( L- p' j4 Z4 z
   document.sform1.checkask.focus();     
: M) E' X. Q$ C2 m8 M& }   return false;  " ^6 [: \) g5 c3 a9 L' g8 B
  }
4 C1 V- u& N( D4 E9 s if (document.sform1.checkans.value=="")
1 g/ s8 h; p; n# `  { 2 o& I* k7 s. J5 Y
   alert("您的密码提示问题答案不能为空");
+ e5 E# r3 k7 t5 R( B   document.sform1.checkans.focus();     
! R& \- ]8 _! ^" K5 y   return false;  9 E" L! f8 p( `
  }8 J* f5 b6 @3 N- x8 z5 ~
return true;     
4 s; R' b: l- ^9 ?+ _  y     
8 z! X' S+ A, V! M0 U. V}
7 R0 t2 V2 r) k2 h% m* |</script>

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