返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:7 M& H" q' G1 s# e, R- o
<script language="javascript">     
1 _& c& ?4 f) afunction IsDigit(cCheck)     $ R6 K  I% \5 d: C: {& n  B
{     
' x& w4 O! H8 z1 F7 J+ A return (('0'<=cCheck) && (cCheck<='9'));     
7 e/ T* ~1 f1 N5 D; z' u! I7 { }     + ~( L* I8 D' C& N, Q8 G
       V3 r2 S+ y5 @! }
function IsAlpha(cCheck)     / g- i9 d/ q9 p
{     
. R) \) T" C9 a, j3 ^+ ?% O" B return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
, R% ]% z! O! d+ z4 [- V }              & C2 c, ~4 B( m
      
2 L6 A; M8 }: v/ E1 [0 Gfunction IsaNull(cCheck)         
/ y1 c' v& g9 c- r0 Q. h8 g: W {         
) k6 r9 v! l7 n( t5 c5 D' E$ ? return(cCheck != " ")         0 Z- N; K& ?" y
}                              
: C5 T- w! U8 q      + ?, @) z+ M" I0 s0 F0 `/ I) w: }9 a
function checkform()     
- K: V% g% B) S" B) D( V4 [" z3 l{ 8 r, t! J* t$ g" ^8 P+ H3 I( W
  id = document.sform1.id.value;     + {8 e2 W. X) a  _' a
if (id == "")     , p% G% ~/ o' L9 J
  {     
2 m9 N8 D6 c, m9 O  alert("请输入注册名");     
# }% i% J: E* S, p. F  document.sform1.id.focus();     7 Z" E! @: m- d% X) ]/ Q9 y. k/ J
  return false;     
- I, M7 @5 |! Z5 L! R1 u  }     
. {1 p# h0 ?1 @- N6 W" p0 b6 q     , Q3 D* ~$ t+ ~; L* U$ i5 Z
for (nIndex=0; nIndex<id.length; nIndex++)     
9 |+ Z9 i% g# o/ Q$ G* Y  {     
2 c7 s" Q& x8 p  T0 h  cCheck = id.charAt(nIndex);     ! J, Y# w, m' n; S0 {
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     , Q& q) K0 D5 G4 s, `# b
   {     
# f/ V; t0 B7 J  k   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     * ?( v1 R- x0 P* p# B1 j1 l
   document.sform1.id.focus();     7 I& x  k: ?) ^( R" W" n' Q
   return false;     
; n, d% e; W) n1 a, L: C$ j9 b( ~   }     2 b$ Y- v! w9 A0 S
  } # }3 O/ Q! V$ u' J8 _
  chineseid = document.sform1.chineseid.value;     / U9 M; z7 L/ i; A4 E8 p
if (chineseid == "")     : j( f9 _" O( d
  {     * y3 m: |% G* m# W
  alert("请输入中文昵称");     & p: ^$ v/ W, r/ [9 M
  document.sform1.chineseid.focus();     - d8 k3 y5 K/ r$ P' w9 ~: x5 G
  return false;     6 t; X/ P% H; t% V1 w
  }    ) w+ K7 g1 a2 d- J. V
password = document.sform1.password.value;     - V) Q4 V3 y& ?$ S( r# ]* H! h
if (password == "")     
/ R0 d, M* E) h  {     
+ _6 d* h9 T$ a+ i, d  alert("请输入登陆密码");     9 {& u8 s/ a9 J! \( \1 C
  document.sform1.password.focus();     # Z( l& H( C$ w, j) Q
  return false;     ! Q1 c. D; j/ q8 |. ?
  } . s( [5 @3 B, f1 A3 u2 `9 g
password1 = document.sform1.password1.value;     
& L1 T$ i! P4 ]2 _8 z7 f1 v' ~ if (password>password1)     ( [8 d0 j, p0 S6 H
  {. @$ S: i6 i+ j; G. X6 @' ]5 ?- o: D
     alert("重复密码与登陆密码不相同");     # @/ o( |3 z, U
  document.sform1.password.focus();
$ z' G/ n' _" |- k+ y5 y2 Q                                document.sform1.password1.focus();     ' p/ A. ~$ m( H$ K. {
  return false;
% u! G3 K1 \$ i; k6 b  }  
1 y" j  a% ?6 J$ Y( l4 A# Kif (password<password1)     
7 R6 t( H8 o4 S  {
- D: B  ?* t5 l- s     alert("重复密码与登陆密码不相同");     
# F# n2 {0 ]* K) t' I3 ?5 T  document.sform1.password.focus(); & o0 m' q% f& A, H8 a8 U3 ?" q5 U# A- O: P
                                document.sform1.password1.focus();     0 n& g- n: ~8 u) M
  return false;6 l. D' n, F) Y* j( U* a: w/ x
  }
# u( C) l/ R' F; j2 r if (document.sform1.email.value == "")     
) P) H  T# v/ s  {     : B" l& s- K! K+ W- @- S
  alert("请输入您的E-MAIL地址");     & N; `, R+ B. j3 A# g. |& K
  document.sform1.email.focus();     
" f& d; E! C- e: t, K; |/ v; r  return false;     3 c- [- y$ j# b, U4 g1 W
  }     ' z/ T% _! i6 ^: ^& j
      
8 A$ h( I9 j$ g' |7 Y! x& D email=document.sform1.email.value;      4 l0 o: C# ~5 q7 I! N
emailerr=0     
7 {) p" S; W& x+ t3 L0 K6 g( x for (i=0; i<email.length; i++)     ' K' [- W- o- R
  {     
  o1 X0 z, P2 o  if ((email.charAt(i) == "@") & (email.length > 5))     
- a, }' J. o* F3 Y$ {7 l" t   {     1 n, x( Z, a6 ~  d. p& h" r, P% c
     emailerr=emailerr+1     9 i% {4 p* M5 ^0 ]( r. G0 |+ }6 g
   }     , u5 u+ O5 o7 l/ x  m
  }     
! s  F+ H3 I  f* c. H- \ if (emailerr != 1)     
5 x. I, S) P3 K- D$ b* h  {     
5 R/ M' L6 M) y! h/ F, e; T- S  alert("请输入正确的E-MAIL地址");     ; L2 K6 ~( u5 U. i/ M
  document.sform1.email.focus();     5 I; F3 _+ \* C, H* _  @
  return false;     
$ t! Y* u* [7 w+ M+ J9 J' C  }           9 z1 k4 J2 k! Y* F4 f3 Y4 I8 V
  
! f5 Z+ j7 Q$ J2 N+ ]* l if (document.sform1.checkask.value=="") ) f; X' Z4 f: }. i) U7 F
  {
) O  I- y" |8 A   alert("密码提示问题不能为空");     1 [0 F' P9 f9 E
   document.sform1.checkask.focus();     
, w# }5 E4 I0 ]+ X  n   return false;  
. p, O& R* Z: {$ T' q  }
% B& F) F5 p% _! f) b( x) i5 q- l if (document.sform1.checkans.value=="") ' a7 P+ q' F1 t5 ]
  {
6 D- D: T$ G+ @$ c3 P   alert("您的密码提示问题答案不能为空"); , R: |0 e! K3 e" J2 R* l+ E
   document.sform1.checkans.focus();     5 ^3 k% [+ L% e& z) B" q: ?
   return false;  
/ X9 w* I# ~0 S/ o8 W) M$ b) ^- F  }! E4 k. n: a( z
return true;     
! W: c/ D, m1 R% ?     
* l5 S' @( L* G& U" z}
; c$ h# ?. \# S</script>

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