获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:& ?  ~8 G' E3 [/ z
<script language="javascript">     
) y: v# c8 J& V. gfunction IsDigit(cCheck)     # |) e: J; h% d$ Q+ L1 S; W- H
{     3 j9 l4 s+ x5 b$ _+ ^9 S
return (('0'<=cCheck) && (cCheck<='9'));     ! j' ]- f; Q  X' p& l  n  w0 u
}     . F& m1 M, T6 q4 ~$ k+ L
     
  k; a7 q- x; c/ Wfunction IsAlpha(cCheck)     # J: V8 @, k6 o$ D# f4 f, {2 v3 _
{     5 H0 z9 }% w0 v$ b
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
  F! u3 @9 M$ v }              
: g) H7 r2 r8 e( V3 B      ; c8 Y1 [: L! F1 t$ u1 O
function IsaNull(cCheck)          5 o; D. w2 X1 \$ q/ j$ R% d+ v( n( X
{          . @# o9 ?& I* t3 m& L
return(cCheck != " ")         ; e7 P) h  V& ^" P- W5 ]# o2 T% I
}                               9 |+ ~4 u- v5 z
      * N! D* F/ E3 ?
function checkform()     ( y2 m& I. V. g% O7 F: V' V# @
{ * _9 S$ o) h# c2 c7 \
  id = document.sform1.id.value;     
7 r  ?8 P9 j$ W' b if (id == "")     1 s, F- q) E& j5 S  y
  {     , ~7 U: U: a; }! ?# ^' L
  alert("请输入注册名");     . w, a  S0 O: E1 t/ j$ X
  document.sform1.id.focus();     % J, B" M( r: [" f' f, ~" P& G" M
  return false;     
. R2 s2 ~0 z* w% a" Z  p4 H  }     
( D( @# M5 O- _1 V4 \( n) o! X" O     
5 A$ @1 e; x: m; [: Y for (nIndex=0; nIndex<id.length; nIndex++)     
, U2 g7 o( Q9 W7 W; p# ^  {     ! @: J/ j) F) N2 j) ?$ r* l$ P
  cCheck = id.charAt(nIndex);     
# D5 U4 k: T& d  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
. W+ [/ X4 i6 d7 S/ q6 |3 D5 M3 U  D% c   {     
2 b( X% K% L1 ~& F0 `3 |- V# L/ W   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
: @$ S, V6 g! j+ j1 U   document.sform1.id.focus();     1 q- H% u4 V- \0 ^2 A. T8 }
   return false;     ' H( K0 C/ T" i8 L- H0 u5 j
   }     ; T( [9 S) e3 Z+ B% R0 R& S
  }
! P) s9 C( Q4 B4 A& F) j. j  chineseid = document.sform1.chineseid.value;     
: F+ y* a5 U2 c/ a+ A if (chineseid == "")     / H& y! ]' @+ K; ]/ @
  {     - E, m1 Z0 z* f
  alert("请输入中文昵称");     
9 B  {$ b8 x" _6 e4 a+ T) Z  document.sform1.chineseid.focus();     / P& Q& m* h% S7 c5 ]- t* J
  return false;     
, U1 _6 |, u3 `! Z( \$ V  }    2 U0 W1 D: y; G' c5 O+ J! s0 ~
password = document.sform1.password.value;     ; V4 u$ C* q' M
if (password == "")     
) d: a; H  B9 i4 H; L  {     3 D  X: i9 E0 B4 `
  alert("请输入登陆密码");     9 B. e4 g  v: a% @3 _/ u- s8 j
  document.sform1.password.focus();     & V: {, c# S0 v, j- E& i6 B- e
  return false;     ( D& m4 f: n$ P8 o
  }
* y' Q* `7 A9 ^% u  n password1 = document.sform1.password1.value;     6 L2 h: F2 N6 U4 ?
if (password>password1)     , K0 n/ X& `4 g, N7 F
  {& _7 m, p7 z$ y" Y: T3 G/ I' g/ g
     alert("重复密码与登陆密码不相同");     
5 T9 m9 X5 D/ u! }$ O1 N  V9 M2 B  document.sform1.password.focus();
8 [# l  q0 P5 j) o                                document.sform1.password1.focus();     
' i( g+ m/ D6 y  Z% K  return false;4 K& A- T' G3 {
  }  : b/ `7 x+ R) M- J' g) x
if (password<password1)     
! [6 A$ r/ D' F, v2 M+ M  {
( f  \! Y8 c) l% E5 }- U* _9 j( t" H     alert("重复密码与登陆密码不相同");     
* p, P1 [: X6 M+ g3 n+ ~  document.sform1.password.focus(); 6 M6 H+ |" t- S
                                document.sform1.password1.focus();     
& l3 [% ]1 f; V& L; I, @3 g  return false;
& D* u* x3 s& K  } $ g9 A! ~# n& P& j* R
if (document.sform1.email.value == "")     ! T# q$ ^' |- c  C. y& R+ _
  {     7 B9 H. w. G0 r7 W
  alert("请输入您的E-MAIL地址");     
5 R' e9 r. O6 l# B6 s( T! \  document.sform1.email.focus();     + i5 d$ h+ H- G
  return false;     
& z7 M) T! d5 u9 h3 a9 Q$ `, ^* u0 h  }     
  x1 _; d1 g2 W# _4 u" m: K0 m      
9 w" J* R. Q0 V, C5 |( H) u3 J; C email=document.sform1.email.value;      1 x) ^* p+ }; x- C3 X, g  `3 Z
emailerr=0     , b* W9 I8 v2 S  x
for (i=0; i<email.length; i++)     ; o* U' F7 o0 E  l  s- R# M
  {     4 b( _* a; [6 V1 {
  if ((email.charAt(i) == "@") & (email.length > 5))     $ K/ Z6 K* T( Z+ W. A2 T; B% |) ?
   {     & y+ b# H; n( H9 F0 w/ W. j+ i$ B
     emailerr=emailerr+1     
- B: r: ^9 D7 e& P! M7 d$ M1 R# c   }     
; K. A: \: Z; ]7 [. x6 G6 W/ X# k& T7 K' j  }     + E: u, j7 P3 P1 d, N; G
if (emailerr != 1)     ' t) C  T( {; R" Z6 d3 A
  {     
* ?' D' N$ ?6 l  alert("请输入正确的E-MAIL地址");     & {$ q( T" d0 `' L; _% u( P
  document.sform1.email.focus();     
+ P7 p1 Y& u7 D+ V- r% x- l  return false;     & W$ w3 P( R/ a# T9 W5 p0 F! q; ~
  }           & C: H' }: e) A
  1 M2 l6 G3 d; D' ?$ `$ ^
if (document.sform1.checkask.value=="") - ^* R, [: ^" i) d$ W' e- e1 c1 t/ F8 N
  {
: Y  f( ^4 y* L3 m5 ^8 ?( V  h% x   alert("密码提示问题不能为空");     
9 y, k' i+ @3 F0 M* t" C   document.sform1.checkask.focus();     
  q! h; d/ ~4 T% \8 a$ \   return false;  
. G7 S( n( H6 x: Q  }
/ U: |$ O9 E6 B if (document.sform1.checkans.value=="") ; a$ }- O" g* T  N# k$ L
  {
( I1 P/ W( J) t' r2 y) u   alert("您的密码提示问题答案不能为空");
1 ~2 w" L0 @% u- S+ q' M   document.sform1.checkans.focus();     0 M; k  s7 o2 P2 A5 c
   return false;  
' L9 y$ B* L( h6 j  }0 k2 j( _+ k! g( f$ X! F+ J
return true;     
7 p4 R6 x! T* f     
" Y' _# e0 Z- x: {3 A% `0 {* q2 ]: m} 2 s, N8 F8 \1 k4 \( F2 Q
</script>

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