返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:# J! s8 _# `2 d" ]6 T
<script language="javascript">     
6 w- W' U) E3 r7 h  dfunction IsDigit(cCheck)     
8 e# ^6 s9 X- H) X0 A/ v {     7 o, n9 B$ ~0 j% Z# u; X
return (('0'<=cCheck) && (cCheck<='9'));     7 a* ~/ A; c. Z! f2 b
}     . i% l2 O8 S. y! j/ l4 c$ F! `
     
% a1 }3 M6 l; a6 g3 \: yfunction IsAlpha(cCheck)     
8 Z. O% N- f5 L/ w {     - T  t& {# c3 G0 S
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     + X: g, }+ R8 V. ?4 ^4 \
}              
" B/ A! r+ t8 u8 b7 B+ [      
& Q) r( l, w) m' r2 L3 _, [5 Pfunction IsaNull(cCheck)         
  k9 @% e" n: T; n6 R0 L {          % |, f- _/ a% B2 ]7 \' {& V
return(cCheck != " ")         + l) T; T. A$ U7 v6 ^* {* F. T
}                               0 }& d7 }! a" t* z; M- V3 @
      / R3 W9 H$ |7 z7 [
function checkform()     5 J, T8 j* v- Y% C8 f
{ # N+ j. U6 U; u! i% X) ]
  id = document.sform1.id.value;     
7 y: {/ x# E# q) q if (id == "")     $ J" Z9 s# q8 K
  {     
/ t  f2 o! d" \; ^! {8 _/ @: v3 u. f  alert("请输入注册名");     
  l! V: v( r3 q  document.sform1.id.focus();     % `8 ]! b% Y  x. E+ I+ ]. D
  return false;     
4 ?8 ~8 f& W. \  X6 M  }     
5 M6 a5 [% V  @4 {     6 k$ @$ U# x" W9 m9 c0 U
for (nIndex=0; nIndex<id.length; nIndex++)     
) U4 w3 [1 a# O; x! B4 _  {     
) d9 }3 x$ O6 }& L7 p* ?  cCheck = id.charAt(nIndex);     
$ ^( W/ C  F2 ~' w9 a9 C  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
' ?9 L% }- X% ]7 r, R1 ^   {     + C- f% l' W% T9 ?. Z# H' A. m
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
* P' O6 K+ Y- Y6 e# a" w   document.sform1.id.focus();     
+ C: s& ]5 M( r( f) b% }5 _   return false;     + n9 o$ @9 k) _  k
   }     " `1 K0 I& N( s& v" Y" l! W
  }
( c( l# }9 w4 t& v4 s: {% L  chineseid = document.sform1.chineseid.value;     8 j  L3 T8 V; k% R
if (chineseid == "")     
: N) |9 s8 F$ W7 s/ x  {     8 L7 x2 a9 X+ A% s
  alert("请输入中文昵称");     
) F2 b6 X/ i! {6 p' ]! e; g  document.sform1.chineseid.focus();     1 C/ X/ g2 ?! u& g
  return false;     # S. `7 L+ d7 T% o- I8 u
  }    - c- @1 N4 X% J& z+ w# R; }
password = document.sform1.password.value;     
: r6 l5 r. f! ?) \ if (password == "")     
6 ]- s5 z, d7 u- W& h. X  {     ) v* q7 }* \2 n' }  Z' r, N4 t$ d
  alert("请输入登陆密码");     - J" ?9 [" |; c
  document.sform1.password.focus();     6 ~9 J7 f- R; O! h: m/ `+ U; ^
  return false;     
7 ?& ?' R. {8 }9 [2 _% W  }
; p6 @. Y$ V$ m6 z password1 = document.sform1.password1.value;     3 ^8 [7 G" N5 g9 c0 w  T
if (password>password1)     % n  }1 Z( _  A
  {
+ |- x4 L" M/ R- k3 Y- k     alert("重复密码与登陆密码不相同");     8 a4 t/ ]# v! Z# S1 I$ A
  document.sform1.password.focus();
& E7 U- R2 p# g9 Q                                document.sform1.password1.focus();       h8 g& \& ~* g1 `) ~( O. D
  return false;. T/ @- r/ k# F; x$ q7 r, q  a  q
  }  
1 D& R8 }' N  b0 \0 Qif (password<password1)     * K; ^3 ?9 S9 y6 P0 v! E  _3 C  C
  {, X! P, g9 L# u, V1 g( I
     alert("重复密码与登陆密码不相同");     
) Y% r2 B; @. s8 j  document.sform1.password.focus();
/ j* A3 X2 P' B$ S! H                                document.sform1.password1.focus();     3 z. K9 p7 Z' y6 B. D7 Q
  return false;
) @6 A. C% q9 o0 b" g/ q  }
4 ?. y7 t$ I% O( b9 R5 k% Y if (document.sform1.email.value == "")     * e) T/ T0 y) D& O( g# O: f* F
  {     
7 Z1 o7 G) O, u4 S+ A  alert("请输入您的E-MAIL地址");     2 G6 @* S2 }, n" D" d3 v" x
  document.sform1.email.focus();     5 r* D/ B8 O4 ?5 \
  return false;     
9 y9 d3 t% P) d$ \- C2 x  }     
$ t2 r* i6 X8 B4 @1 V3 m      
& z& G6 U2 Y- \1 Q+ \) U email=document.sform1.email.value;      
& v+ K* ?; S3 M& ~, a# M$ ~/ V% V emailerr=0     $ ~, V5 c- F  c- n" ?" i9 ^& M, p
for (i=0; i<email.length; i++)     
6 A: ~! i& s+ w# v# N$ ?  {     * O. g; c: u7 l. w2 k6 n; d  j
  if ((email.charAt(i) == "@") & (email.length > 5))     
" |: I; X3 @7 H1 J( @% Z- z. W   {     
1 v) x2 I1 U1 k0 I7 D     emailerr=emailerr+1     
7 A) ?1 }9 @9 H8 [6 l5 {+ M   }     8 E1 W6 k, L+ ^0 Z
  }     7 h9 ^3 Z4 W; C& x8 I
if (emailerr != 1)     + V% x; I6 E4 E9 _- l/ [5 [
  {     
' S; l& @# m4 S/ W4 b# l  alert("请输入正确的E-MAIL地址");     
0 G* o. k% M7 }  document.sform1.email.focus();     
6 O8 f% Y" ?- N9 u- b; R  return false;     ! j3 {; D, o$ K0 I' f& `3 Y; u
  }           , F) v9 i6 p. u- ~- `6 L
  
" U8 F/ K! ^  ~) ~, X if (document.sform1.checkask.value=="")
6 A" T7 {8 R6 R( q' @1 Y& e3 W' X6 y+ q  { " x7 r+ @0 O6 x- x  [# Z
   alert("密码提示问题不能为空");     / y4 m; N' i4 ]8 K* a4 I
   document.sform1.checkask.focus();     3 i) O0 Y& M" B: Y. \% c( ]
   return false;  & g( g* S2 M( N
  } 1 V+ h  Q. R$ e& f' O- C1 z7 S
if (document.sform1.checkans.value=="") 3 @7 }0 _, e* P9 i4 G( \8 T6 l3 f1 f
  { ' N2 ]1 R* f) b5 h+ [  f
   alert("您的密码提示问题答案不能为空"); / n# X. w- \: X% \) }* ^
   document.sform1.checkans.focus();     
+ m% \3 A' r2 O; ]   return false;  
2 R6 u; n1 p$ A- \" x  }. C  c4 H+ g0 _& u
return true;     / [/ \& _3 }; k" ]6 Y) h# F
     
- ~* s6 A1 O1 g} 0 h% r& L0 T$ E: p& V# f6 c& t, {
</script>

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