返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:: T: _) p7 S, g
<script language="javascript">     
: B5 E& k/ J5 N2 Dfunction IsDigit(cCheck)     6 x0 b% s% J8 f
{     
. t, Y7 a  {& B, R; m: R; `! |3 v return (('0'<=cCheck) && (cCheck<='9'));     ; A! {% y& R, N5 i! I
}     
" P, ^( K5 Y# R! C& G     
+ |; |8 c3 U. E# [4 d# Wfunction IsAlpha(cCheck)     2 w8 l, l( G6 |
{     7 H; }: O. Y& @+ a( ^0 I/ S* q% J
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
) ~3 ~+ _" N2 @7 J( f  c* s }              # ^3 j  `; c+ [+ @
      
# A# {7 G6 r5 G/ Q5 j2 S: i0 Vfunction IsaNull(cCheck)         
1 [/ d: A  }; P+ E2 C+ r {         
! D7 L1 J3 Z' ~- l, ^+ \ return(cCheck != " ")         
0 V4 o) X* Z7 c, ]1 y0 h3 H }                              
) E  B3 c* X. F! a      4 {$ U% J& W4 M1 b" H8 K$ R
function checkform()     
( K! I( ]- ^4 |- O: G{
) G  b3 r+ Y+ x. P+ T" f: }  id = document.sform1.id.value;     2 z: ^6 T1 [# A
if (id == "")     # e4 }, z7 j- F
  {     & a0 s& e; x& Q2 p' g
  alert("请输入注册名");     
4 {$ b! y( M: _0 Q+ o$ N% T) U  document.sform1.id.focus();     9 `1 V. H$ B8 S$ f' c) L( S
  return false;     
3 [# w+ V* }3 L3 X% ?# z  }     
+ p! M' ]6 a, c     
5 m5 T& p) d  S% q! S3 Z$ G for (nIndex=0; nIndex<id.length; nIndex++)     
( O! }; p- f! j+ ^8 A  {     5 X( }% n3 A0 k  }. Y" @
  cCheck = id.charAt(nIndex);     $ q' u5 L" |3 ~$ I, x- A
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ( S4 v/ D, O- O" I
   {     2 _4 a2 v3 O" }( Y# y# r/ K5 u1 F  z, ?0 u
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ) i, }. C* R# F
   document.sform1.id.focus();     3 H+ l# y. d$ j, m& v8 j
   return false;     
+ \) ]* K! t% @! g) r( F5 l1 f   }     2 k- h9 f; _4 H6 ]3 w
  }
2 {* z4 U& z9 T8 H' ?0 ?8 K  chineseid = document.sform1.chineseid.value;     
1 q# }6 Z0 y9 o: P if (chineseid == "")     8 X# n2 b6 c  P* e* p# Z7 s$ E  M0 H
  {     
4 P; j0 q9 M; o0 m/ B; q6 ]% I1 ~( Z6 v" U  alert("请输入中文昵称");     
+ x  L# Z# ]7 f- P0 G  document.sform1.chineseid.focus();     
' c0 ^, x7 k$ q  return false;     9 Y& N7 K, K5 }, m3 ?7 l. U
  }    2 D* A' }& E' R0 _( [5 b' W% ^8 c. w
password = document.sform1.password.value;     2 w# g" ~, F+ p
if (password == "")     - a; o3 A. T% H- J2 Q/ a9 j4 g
  {     
. W2 \  w( K. l% ^; b. z2 }: b  alert("请输入登陆密码");     
8 m$ p3 X6 S% K4 R$ _( K  w  document.sform1.password.focus();     
0 f% j1 D9 k! k! X2 e( C  return false;     
6 r1 F) R1 I! u  } % H& u: c: o4 M4 ]1 R2 |4 C: N
password1 = document.sform1.password1.value;     
" _4 v! B; H/ q- F* q% Q if (password>password1)     
" M4 D/ z) {. c% Z3 g  {
' x# Z4 k0 N5 c* K     alert("重复密码与登陆密码不相同");     
9 O8 F, }  P; K( y, E! W  document.sform1.password.focus(); + q" X& k+ g  |# P/ L
                                document.sform1.password1.focus();     
( S6 P$ a( {2 M" n6 p  return false;
: G* p( ~2 W# W6 E; u  }  
+ [/ q1 J5 q# B( m, ~; A& \if (password<password1)     
6 }+ m6 U) E1 j2 s  {
- r" G7 }" q5 ~     alert("重复密码与登陆密码不相同");     
5 v/ ]4 P4 d. d1 s  document.sform1.password.focus();
# T) T* q* R8 M* n$ L                                document.sform1.password1.focus();     5 L6 p7 X5 @$ G$ ?6 N! a
  return false;3 F! m0 H( j1 {: @3 c  K) ^8 w" e
  } 8 @# n, \: U3 Q2 b! H
if (document.sform1.email.value == "")     
: a6 x2 f" m) F: ]( R0 H) L  |  {     
5 l: X( r  \* q  alert("请输入您的E-MAIL地址");     $ b6 g7 X  V- C  D4 R
  document.sform1.email.focus();     9 E- |/ ~- R, k; `
  return false;     
  s, D: \- p$ E: h  S4 v5 M- [  }     
: N  N& A9 S  Q+ k8 [      0 K0 Q; W5 J, p5 z/ D1 i
email=document.sform1.email.value;      - k4 h! T7 V* S. u2 ]( s
emailerr=0     ; Z9 T. ^5 k" \( Y
for (i=0; i<email.length; i++)     
' W! A7 B/ `* r  {     ; c3 j; c, g' E: d
  if ((email.charAt(i) == "@") & (email.length > 5))     
0 h7 e6 s. p1 I5 K" _   {     
1 t; r$ ^6 M5 t6 p$ s     emailerr=emailerr+1     . o- P& X: q9 X$ A/ z
   }     
1 w1 t/ \1 x1 k1 H, c$ ~  }     
& `8 f  j4 \5 l( a$ A4 t7 Z1 q0 U. z if (emailerr != 1)     
% p2 I, V; O- K& N. }  {     
4 A* H/ J, @! ~  alert("请输入正确的E-MAIL地址");     6 ^2 B1 ?! {- I; m2 r5 A
  document.sform1.email.focus();     3 }0 y5 N+ Z. ^! ^& z$ j
  return false;     
( b2 V2 b! J# T' C! v  }           
; V9 `9 L9 V9 l4 j; K$ @  
! ~" w3 C# ?3 b* i if (document.sform1.checkask.value=="")
7 T# |: e' ?. y1 b  n  { ! i8 C: Q* [; n/ i( N+ D% s9 l
   alert("密码提示问题不能为空");     
% z6 X& L' ~& ]& u   document.sform1.checkask.focus();     & e+ O0 O7 G4 h4 n1 P
   return false;  
9 I; w& H: T: j/ I7 b  }
! \0 d- r, V. L, I/ ?% Y if (document.sform1.checkans.value=="") 3 v" V/ Q2 N& U: N# ^9 T
  { , S; o. X! c. m; v, C
   alert("您的密码提示问题答案不能为空"); ; \' l& K/ h5 x+ T; n; Q5 u
   document.sform1.checkans.focus();     " Y) D. N) u# j( l5 J
   return false;  ) j- {) ?# ]! |: \( i! R1 e" x- L
  }
" e. z' E- }0 H) C* M; Z2 \" w1 B return true;     
: ?! C* r/ g$ t3 S! J: Z& j     
# z3 I% i+ A, C} 9 d" T! W4 b) J1 p
</script>

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