返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
  }$ S+ Q: q. s+ `, t' x<script language="javascript">     
$ X( A3 T" T2 b  Pfunction IsDigit(cCheck)     
- B4 a5 T5 [. W( G' z {     ; H4 v6 M% G: r0 Z  L- R- k9 R
return (('0'<=cCheck) && (cCheck<='9'));     
8 I' a6 l5 q& j& T& [, M }     
' E) g. s( f0 r7 g7 n; Y2 e     
& ]3 f% s* ?) B% Yfunction IsAlpha(cCheck)     
' F& r! D! ]- t1 W' W {     7 z/ R; n" O7 e0 u7 F
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     8 n9 r% `* q, {: L- ]6 z5 D
}              
- K& }0 V( `+ }5 R" ]4 h/ X      
; E  g( \& b1 s# Z4 @3 C& a/ ~( ufunction IsaNull(cCheck)         
  _) ]; r, H7 u' ^ {          ( B! ^. i1 g  b8 S! N- U  x
return(cCheck != " ")         . Z+ J. t# e, S
}                              
* A7 z0 w/ p$ d( Q7 t      
; G$ C/ l1 e; |% t8 m; y( p! o  \+ zfunction checkform()     
9 D* O+ K( I) u9 z! d{
) w' B- l! }4 ^7 @  id = document.sform1.id.value;     + T0 ~9 F& ^+ _: E
if (id == "")     
3 c! H5 Y7 D( Y! m& p2 p  {     
- j' q$ {$ G' \9 d5 ?- C  alert("请输入注册名");     ! p0 Q- f- W) T6 y
  document.sform1.id.focus();     
: q' @2 C7 u  A9 y7 b- v9 k  return false;     
8 F  G+ Y, w/ a  }     
7 e3 E5 t! h0 w# z: g3 W1 f     & k4 V2 |/ J$ l3 B& q
for (nIndex=0; nIndex<id.length; nIndex++)     0 }; O! L8 ^5 K! k  H
  {     
# @6 N" |9 o& `/ H  cCheck = id.charAt(nIndex);     # C" S/ a2 P4 t6 X
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     , q8 u& S1 x  [4 Y
   {     
* x) G  [+ g) K* @   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     9 |) z$ e* ^9 H1 p- `, I) N
   document.sform1.id.focus();     5 T2 R5 Z: _. I! Z  U5 X- G
   return false;     
; P% t- k) o( s+ j; G   }     
- u- s- b1 ^- Z6 W4 N  }
, Q: n/ q' C9 y3 j# P5 S: @# G9 ^  chineseid = document.sform1.chineseid.value;     
3 @* H8 t8 q! D# J9 E- Z0 d, d0 ~8 w if (chineseid == "")     
6 Q4 H7 z% d8 Q. V7 c. c  {     ( Q1 U6 K8 ?! c, U! W# `
  alert("请输入中文昵称");     
0 S" B6 ~: b  y: ?4 M  document.sform1.chineseid.focus();     
( Z- v" x) r- x% L) o3 [: V" ^  return false;     
) {# e% I: ^! N  }   
2 E3 Z* K' q" d+ O: P  p password = document.sform1.password.value;     : U9 d- w9 b6 B$ {0 X' L. f5 r
if (password == "")     
" ^: y% @$ m( T2 h  q, [8 y4 l" ~: p  {     / y8 ]6 E  X( `/ F4 H
  alert("请输入登陆密码");     $ A' t% z( R* t7 [5 b( J! O" \
  document.sform1.password.focus();     
% \0 U) l9 D. A0 q; `9 n  return false;     
! A2 N7 i1 n( v4 @( y% [  k  }
; S* [6 q* f. ^ password1 = document.sform1.password1.value;     
4 ]/ \$ f# m+ e+ N7 z0 O7 c+ ] if (password>password1)     8 M( N" R6 i$ M; N1 s' B
  {
; B7 p7 `( m" u$ M- k     alert("重复密码与登陆密码不相同");     7 |3 v2 [+ Y# r1 O2 R" f
  document.sform1.password.focus(); - Y/ m" y" C, ]9 z  ~
                                document.sform1.password1.focus();     
$ ^5 M9 J$ C" f) v: Z1 a  return false;
& Z/ D$ ~4 z3 n/ P% l: J  }  ) }2 C. m/ W' Q
if (password<password1)     ! h/ F6 ^4 c' O  J. v5 _' x6 V# Y
  {
$ Z' e. J, a" j, h; [, m$ m8 h     alert("重复密码与登陆密码不相同");     5 q, l" p2 i5 b* `  ]6 D, k6 g7 j
  document.sform1.password.focus(); " E& p  y- H) D  [
                                document.sform1.password1.focus();     
1 E. M0 G. ~' \, U2 F+ [0 T  return false;7 q$ V2 U+ |9 U! n
  } 7 [* U$ }$ A# e( I4 u
if (document.sform1.email.value == "")     : v/ `* M+ m: n+ ^
  {     
  F0 v$ `$ \6 F. `- j4 W  alert("请输入您的E-MAIL地址");     $ V' O. X( B7 Q/ P/ ~; Y: G: g
  document.sform1.email.focus();     
, f- m2 T8 n) i3 a* J  return false;     
3 t. n, ]& j, ^  }     
- [5 t+ o* a- M      
) u0 T- _8 @& `: I* d% \ email=document.sform1.email.value;      
8 N6 B- H5 Z* E7 |: D emailerr=0     8 f9 D, b$ ~% K
for (i=0; i<email.length; i++)     ' @7 ^. S9 C# v% R3 M9 G
  {     ! w' r! D# V5 r$ m: F- X
  if ((email.charAt(i) == "@") & (email.length > 5))     8 |. q0 U& J) a0 {
   {     - L0 U  s' @6 R& W+ R% k
     emailerr=emailerr+1     7 ]/ m& Y+ ~$ k
   }     - T$ n  u6 I; a3 S% A
  }     $ h9 F0 c9 c, B: X& o
if (emailerr != 1)     
7 ?8 ?7 o/ n# s, U  {     
' j, P5 J3 t! z8 u3 d  alert("请输入正确的E-MAIL地址");     
+ W& @0 [2 }# @; t1 L, `  document.sform1.email.focus();     7 z/ c/ R0 u( c) m) j
  return false;       D$ _1 t# c+ e1 R
  }           
0 N$ J- |7 [7 e9 V% C, A- ]. R  " [# q# G. O% Z7 U7 |" C
if (document.sform1.checkask.value=="") ' |; j* W. `- u# T& K
  { , p  b* d9 F3 I! R
   alert("密码提示问题不能为空");     
1 w, U7 G1 J. ?- B. l# O   document.sform1.checkask.focus();     0 l7 v- G# H% h( G& X  P2 K4 _3 A' l
   return false;  
0 A, U, [' m- t$ l  |1 g  }
3 |! D* `3 t' i; q, z" p' _ if (document.sform1.checkans.value=="") " ?. s& l. p* f' G- a* U6 r
  {
2 V) ~( D7 ]9 a9 @# `   alert("您的密码提示问题答案不能为空");
5 {& c( @+ ^+ p. ~& t& s# Q) ^   document.sform1.checkans.focus();     
3 g1 q) G" }1 _   return false;  
: R& v6 X1 W$ k  }
% h8 T; e7 y  K" V% u. ? return true;     
' F) U9 e8 U, A( J& i, s     
" l+ F7 [9 }( m; u9 R8 E& m; p} ! @8 V' G/ u. M6 V* [! ^, a/ f
</script>

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