返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
: }7 S* i: u' ~" ?* |<script language="javascript">     
3 ?$ H% @5 e' O. d1 ^3 H/ F) \) ?function IsDigit(cCheck)     
; F) Q6 [% R5 m: Y% G {     
9 c$ v* ?" N3 K- o return (('0'<=cCheck) && (cCheck<='9'));     
8 W* D! t, L& n }     5 Z, w6 t, v4 l0 H: N, n
     
' k8 {9 m: j4 r3 |- |function IsAlpha(cCheck)     , _8 S+ q3 t# i7 e  j" x
{     
4 `, f0 b/ u! W! D) i# h/ s return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ! i3 Q* z+ k3 ~! O* P$ n
}              
, D3 S4 I  y' A# a& I      
; I) G: }4 K, M8 I; ^- j2 p9 cfunction IsaNull(cCheck)         
: \/ ~, n) O- a" g {          ; L. g- ?% A/ D+ G
return(cCheck != " ")         
: j/ d+ `: F( q. _' L" y" e }                               ' m' ~3 X" b' P+ z
      
- @. C/ z1 F# S1 T3 x$ B( `  dfunction checkform()       W+ y3 a+ l% {$ u' k: @  A0 V
{
- ~3 O- Y* h6 P/ I1 I) V; w; B; y  id = document.sform1.id.value;     
" S/ y+ t# R# T1 I if (id == "")     
3 r& h. g+ n' o0 O% g" ^$ X+ ^  {     
9 D! s8 r/ ~8 W+ w. g  alert("请输入注册名");     & S7 ?0 ~6 s% t* h- }
  document.sform1.id.focus();     ) m. N6 l1 H1 H5 a* {
  return false;     , ]* S% n7 \  ^9 `3 s& J9 l' Y
  }     
* ]' d- b  r7 ~     
/ B- g1 C0 ~" @8 r for (nIndex=0; nIndex<id.length; nIndex++)     
4 D5 d+ |2 |) s3 ]  {     
7 V+ W$ y% f3 k+ D6 x  cCheck = id.charAt(nIndex);     
3 y2 H5 L. S. \1 _  m  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
+ ^7 D' g# O. L; P" a/ V6 d   {     & o0 R$ e2 z9 z- ~' [3 `
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
% {/ a. j  f' x/ @% x. G4 ]: x3 e   document.sform1.id.focus();     
6 N! Z. v6 K* P# L$ `' v  `* }   return false;     
* F) D" E1 u) |3 a) m; s; ~0 M; {   }     
7 I  b. B9 [, |. ~' d8 N) H  }
! L) p. }1 S: \8 F& q. T5 C  chineseid = document.sform1.chineseid.value;     
0 \2 j7 v$ }$ ^& B% K4 B* N2 B+ x if (chineseid == "")       B5 U3 }; g* c& A$ l% I
  {     
: d1 h0 T" s. L* H) N  alert("请输入中文昵称");     % p3 h+ G# ]; q+ ~4 @8 w
  document.sform1.chineseid.focus();     ( o. e, s, T, @6 X. d+ W
  return false;     
  k$ H8 H, r1 S$ V" \& l3 l  }    & N# `# s: A& r* o4 Y
password = document.sform1.password.value;     9 y7 i" |7 ^1 |  Q( t3 Q' h
if (password == "")     
5 h$ T# \: y$ j  {     + p2 E  }0 \, X& A
  alert("请输入登陆密码");     
* b2 i5 [3 k$ I% A3 I$ G  document.sform1.password.focus();     % m9 X( I8 T/ T% q
  return false;     
" t1 a7 @' c3 s4 o& y) k4 `& x0 u  }
% J1 a' P$ D0 d* V6 V password1 = document.sform1.password1.value;     
' E* K2 V* ?: f2 a0 h0 f9 I5 d if (password>password1)     8 E# }! \5 L6 m3 t: P0 l: H
  {
& \. L3 H3 f: r& Z# }' d* `     alert("重复密码与登陆密码不相同");     
3 }' i! o$ W2 L, G/ ?& E9 p  document.sform1.password.focus();
& V% O/ b' @- _% N/ t. U8 f                                document.sform1.password1.focus();     7 |6 |8 p, b8 ^
  return false;
  Z9 _+ ~) ~. D4 O. @+ l  `  }  
! d9 Y% m. J7 w% J: T' tif (password<password1)     + w- i' J8 [' h/ M! i5 K/ _* }3 m
  {
. ^; [" X! ]+ Z* x$ e+ d% v" a5 r7 N     alert("重复密码与登陆密码不相同");     
8 ~+ q% D9 [6 U' f3 M  document.sform1.password.focus();
, Q! K5 B9 x) U% j; I" c! g* n% j5 \                                document.sform1.password1.focus();     
: e, a% S5 x0 p  return false;2 E$ i3 f" B- A' N  j
  } $ b: Z% a+ Q3 j# u* u0 z
if (document.sform1.email.value == "")     5 _1 R; `8 L+ D2 v- Y% p
  {     
( Q* m2 T& L# W) \  ]$ ]) n  alert("请输入您的E-MAIL地址");     
7 d, U1 v: g  ]2 d  document.sform1.email.focus();     ' l0 f8 s) F' F) w3 {2 W
  return false;     
; v& v$ ~* e9 C& P  }     
: H& Z, Z5 U0 T* R, `      2 j1 ]! |- i4 m* i) }5 }7 l
email=document.sform1.email.value;      ) a1 m+ |) d, U  q" X
emailerr=0     2 t0 \8 [+ R1 J  B
for (i=0; i<email.length; i++)     
6 [# P) K# J, f7 P, }  c  {     
8 A8 y  y- W; T* {* J  if ((email.charAt(i) == "@") & (email.length > 5))     
$ V5 U' U' i5 N) M   {     ( ?# k1 N- U: v  L
     emailerr=emailerr+1     8 Y  v& m! K9 e
   }     
  _$ d) w) ]" \8 b- L4 D  U  }     
1 {; i5 L: ?, O  P, T+ P* { if (emailerr != 1)     
. B3 r4 \/ |! k, W( x$ j) M5 b  {     9 E+ J! p% |$ V2 a8 v5 x. q( A
  alert("请输入正确的E-MAIL地址");     
5 h# Q$ i4 M( Q1 M' ~  document.sform1.email.focus();     / p0 X( l( o& V( g; K% a( J- }' A
  return false;     & D5 v) a9 m$ v
  }           
* c! d2 I  _5 m7 ]  0 z4 I: L( A) b5 K3 O
if (document.sform1.checkask.value=="") 5 {; h( E: G( o( }4 K+ z* u
  { 3 l% f% O9 y+ [# @  C( i. z1 V% ^
   alert("密码提示问题不能为空");     . [0 u' K( E3 O) o, V* Z- ?4 }8 f
   document.sform1.checkask.focus();     - j4 ~, @9 b9 b1 N5 F5 t. E
   return false;  
* B0 [7 [  \0 o0 w; f% y9 Q- T  r' v  } ! K4 @: w; C. E' n( h% Q% ^" }
if (document.sform1.checkans.value=="") $ k7 Q! c+ E7 A! l' Z+ e; X0 T* n
  {
3 y/ |) H2 b- V2 p: {+ a% m$ N# D6 G( W   alert("您的密码提示问题答案不能为空");
) m+ y! c5 w' B4 L9 ?   document.sform1.checkans.focus();     
9 Y$ a3 t* e, s9 u( B7 M   return false;  
$ G! Z( r3 m" ]% u+ D* j# Y  }6 p8 b8 a% ^3 R0 u, g: r
return true;     1 w7 g9 i. M/ `
     
; S1 D3 J+ f% @8 g8 {4 \}
  M7 I  ?8 K0 O2 `! t</script>

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