获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:4 E( K. h6 l6 L
<script language="javascript">     * D9 {+ e, l+ y( i, ?, a
function IsDigit(cCheck)     6 Q3 a( L% d9 i/ J. Q
{     
9 V1 g0 P# v# {' L. A return (('0'<=cCheck) && (cCheck<='9'));     
( f0 p4 X" K. {* L }     
' U3 Q% q3 C0 ?3 q* N! @3 i# b     0 [8 [4 B5 \! d  \, m" [8 I: f
function IsAlpha(cCheck)     
' [" i& r8 R3 u% b2 m# c {     # |/ E! K9 E4 n2 U; |9 k
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     + }3 _* a' m( c1 e
}              * h2 E" c9 `/ B; G, _
      # v' b: }6 c6 k( J
function IsaNull(cCheck)          # ?: i9 A6 P2 \. c
{          / o# T+ X* t9 G
return(cCheck != " ")         
6 G1 x7 m$ e* c4 c7 N" u }                               - Q4 B% D1 q0 P7 ~4 m. {  u* Y
      9 F+ g. `9 E6 T
function checkform()     2 U) e6 _5 `8 N8 }2 S2 G& f2 ]) u/ |3 k) d
{ 7 n2 M' h/ f; I0 S- a2 k
  id = document.sform1.id.value;     / M0 @6 y6 e: D0 r# v! Q# K
if (id == "")     + p$ c7 \1 ]  }" h: n+ n
  {     
5 }# \4 N1 q! t6 I: k; n8 P  alert("请输入注册名");     
) b9 A/ v3 a/ w* e" n4 o  document.sform1.id.focus();     
# m$ D0 q9 s; Q. P6 X( m  return false;     ' H% E; }  ], L
  }     + V( {" x+ e5 e. [8 Q# p
     
+ N$ A  b" C' I; c8 B! n( `' j for (nIndex=0; nIndex<id.length; nIndex++)     
0 e* x2 q* X/ q% |  {     
. y7 m& _' s! w. G) O  cCheck = id.charAt(nIndex);     
$ K, y: L. X- X1 Y# \$ `% U7 K7 e  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
1 D2 t" B6 O, D   {     
6 h- O/ l" L" S( s1 }0 s5 \* k   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     / ^9 X, ]% }* R
   document.sform1.id.focus();     
0 h: y, u9 f* T6 g   return false;     
8 x; o; L6 f6 v( V  s, \& V0 Y   }     # s5 Z9 F' @! y, F& r, T, u' X
  } % M" z( E' B: C' ?) P% ~
  chineseid = document.sform1.chineseid.value;     % m. g2 d  I. I( g0 H
if (chineseid == "")     
6 v4 O" J; T* o1 o/ ^  {     1 C; Z( D0 P# ~" [! m
  alert("请输入中文昵称");       z& @6 |7 ]+ e& a+ \, C4 e
  document.sform1.chineseid.focus();     
  G0 s, S% {# ^9 [2 [  return false;     . {0 u8 ]2 r  m3 f, a& I, d
  }   
8 j, q$ S/ w  \) Z. Y password = document.sform1.password.value;     
+ c1 R. O6 A1 E2 e  X  U, @ if (password == "")     / J1 L2 P7 u8 j6 d( B$ }
  {     , E, N- R3 m; Z9 E
  alert("请输入登陆密码");     ! P6 S5 {( c. ^: S$ ?
  document.sform1.password.focus();     
7 K  a9 D9 [0 K3 w2 b$ h  return false;     " t1 e4 _5 m# k: r1 U7 S/ O7 R6 p- F
  }
; z% e+ m5 `# ]+ x+ `1 j; J password1 = document.sform1.password1.value;     . m9 w: y1 S, w' C
if (password>password1)     
* x  x) o9 t2 E( Q' g1 E  {( ^; ^$ R9 l( P$ c9 W: @# X6 k+ n
     alert("重复密码与登陆密码不相同");     
# m! X/ K0 v. X& T1 \- E) _- C  document.sform1.password.focus(); 5 ~. R8 z0 H! O4 c% u% _7 H3 D0 Q3 H+ n
                                document.sform1.password1.focus();     ( D, `9 ^0 K; i, ~
  return false;/ j6 J. i* n* L/ N
  }  " G' H; v4 U+ S. t
if (password<password1)     
# G/ F( N9 A- G! ~% {  {1 Q7 ]( ]& U4 z1 C& y
     alert("重复密码与登陆密码不相同");     
8 p. d/ b2 _3 W* B$ i  document.sform1.password.focus(); ! j, f9 c* F5 t+ D# z
                                document.sform1.password1.focus();     
, t  E/ R- x( J2 c, S2 ~  return false;
/ t, ]* q' N- B; g  }
7 e5 u+ S% f! k if (document.sform1.email.value == "")     + m, G$ {( j1 q, ]* C: m
  {     
) O+ ]: M* [3 V2 I  alert("请输入您的E-MAIL地址");     
' c$ u( F/ k( P4 ?+ H7 ~% _. C  document.sform1.email.focus();     - }7 q; \) y- |! w$ C0 m. q
  return false;     
& S1 U! y; a& }  b# X  }     4 C$ r6 I' V9 `6 s, N% W
      
( L3 C: T- ?. I8 N" y email=document.sform1.email.value;      ' Z+ `" i5 x: b8 }
emailerr=0     
9 }" R, Q  w* O% `/ U for (i=0; i<email.length; i++)     ' t2 k9 q4 A. |* Q
  {     4 j. {1 R+ D' I6 X3 l$ K2 @9 I$ L
  if ((email.charAt(i) == "@") & (email.length > 5))     " w* C: x+ \/ r0 Y1 S
   {     
  O8 n. T2 J( K6 X     emailerr=emailerr+1     
/ L+ z5 a' ^/ O+ Y6 g& [, |! P   }     - T3 i' d4 F3 T" R
  }     , X) ]* f! U. q; U
if (emailerr != 1)     
. k& ^6 V! L' F" R  {     
+ J9 f; H$ \* D/ ]; }  M2 }' v" r  alert("请输入正确的E-MAIL地址");     
1 r5 Y7 h9 c$ ~  document.sform1.email.focus();     2 |: o; M. T" m4 N/ t7 L
  return false;     1 B1 h" S% Y8 w5 ^) q
  }           
  J; G4 L5 e* L' U  
; e1 p$ h+ u; j* D* @3 @ if (document.sform1.checkask.value=="")
% i% Z5 ~- y+ t, n7 t( C2 H  { ! X) g% t( }" s
   alert("密码提示问题不能为空");     
% \1 J3 o+ c9 h4 T5 G7 c$ w$ ]   document.sform1.checkask.focus();     
: @( ]3 C: P/ v3 ?* N   return false;  
5 i$ d% G! r9 n" s+ Q  } 1 o  B2 P" \/ j2 u6 I
if (document.sform1.checkans.value=="")
+ n- e! x" z, t3 L  {
# }% \5 v6 J/ V2 {   alert("您的密码提示问题答案不能为空"); 1 e7 C" y( m! y% ]- e7 H7 Z
   document.sform1.checkans.focus();     % @8 c% [! H5 d  L+ K: F
   return false;  
& J- L' g3 b" x5 k. M+ n/ l' m/ E  }
8 t1 X/ i: Y9 w! A# f return true;     
" @8 L8 b. o) ~, Z$ O     ) U& @1 P7 _9 R. ~
} * |5 d( w. ]2 b" \7 ^/ M- f
</script>

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