返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
' s9 a! }* G. r& q$ C9 S/ T<script language="javascript">     
1 }/ P$ C5 Q8 Pfunction IsDigit(cCheck)     . A2 E# K# g* C8 `/ T# j
{     
4 F4 u0 |2 G/ Q9 \# ? return (('0'<=cCheck) && (cCheck<='9'));     : X/ B  z6 y5 _* S* B
}     
1 J: E5 l$ H. }% r0 N% ]5 X0 l# a     5 I+ @3 j" Z% Y8 C' {
function IsAlpha(cCheck)     ! g7 C/ ^) _/ t
{     
8 S* E, x: \9 e' y% W) Z return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
( J! a( U7 b; `6 H# e }              # L, s6 w" l- z/ P3 V7 x- `: O
      0 e2 j: _$ K' w& L1 L
function IsaNull(cCheck)         
) v) U6 e$ Z: M, I- Y% C) ~; A1 \. C {            t0 J  u+ ?3 s# V8 n! R
return(cCheck != " ")         " ^) v1 [' V: V* {  H
}                                 `9 S, I$ E. J3 r$ x# a
      
7 Z* i8 Y* A9 n: [! F( Pfunction checkform()     ' F4 i$ e6 [( `7 D1 s& O
{
# z3 ^1 f* p* T; {* _, H  id = document.sform1.id.value;     
9 |: v' `: n1 O' V- C if (id == "")     
( u# j' W/ T) c# ]2 G$ H. f; `  {     " f) [) ^3 M% |7 ~
  alert("请输入注册名");     1 d6 s# ?" z+ V" b9 j* X/ V& {
  document.sform1.id.focus();     3 A8 @+ Z. |3 B9 O5 t$ R
  return false;     
7 H: D1 A8 |6 _% V. z4 e  }     , Y4 z9 a: ~4 b3 Z" [
     : |& y8 n* x9 j
for (nIndex=0; nIndex<id.length; nIndex++)     2 N  X6 r: ~2 w% u7 @
  {     
% G6 ]1 s) X9 {1 ~5 l% ~! K0 h" p+ H  cCheck = id.charAt(nIndex);     
' m: z# A) _; @4 H1 c- w  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     * ]) f3 R4 j6 r0 {. A3 m$ c
   {     / A. a' x' `% y' n. u. L$ x
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
2 Y& x! z/ R$ b6 Q   document.sform1.id.focus();     " N4 f/ j" g$ M( h
   return false;     % }7 ^: P$ f( B/ H/ j8 r
   }     ! U: E8 ^6 W  C. C- S4 m" v, H6 X
  }
* q. j* r# G+ h7 c  chineseid = document.sform1.chineseid.value;     
: E$ `+ @' n7 K- I" [0 l: ^ if (chineseid == "")     
8 B; ?  e+ f# _7 k  {     
/ g- t+ I9 z* `7 s: h1 c* G  alert("请输入中文昵称");     
: b9 i: X" ~2 z! z/ m& B: P  document.sform1.chineseid.focus();     / n& r% c3 Q5 g! w* }% W  k4 o$ X3 _
  return false;     
& o- `- y0 w  \3 Q6 H' \  x  }   
( \0 B. g4 t0 {' f0 n/ D5 G password = document.sform1.password.value;     ( D" c/ B7 J1 @- R
if (password == "")     
) b% I7 t# A3 ~% b' d: l  {     & ~. l5 [, \( X/ n
  alert("请输入登陆密码");     
& Z- f; D, d! H, a; {6 g+ w  document.sform1.password.focus();     
+ _$ m6 J, _& n  return false;     6 v) h& ~2 |; |$ G5 f. j' e
  }
4 P0 v- K, c3 J& k2 Q7 [" } password1 = document.sform1.password1.value;     
( G4 n* M9 H- _( [6 V if (password>password1)     
  s7 a2 o& `. G  {
3 ^& s, F: [7 ~% z/ f6 Y1 H     alert("重复密码与登陆密码不相同");     5 P9 m5 J( t6 W: R. e& P
  document.sform1.password.focus(); " H. ?( {3 }* r. \
                                document.sform1.password1.focus();     5 ]: O* u1 E% c2 G$ l% P' X4 _
  return false;0 E6 e! f: x" _& H
  }  & @  I1 L- X! x& n' t5 k. M$ V
if (password<password1)     " d& m* v: F& @1 Z' X
  {& I( X  Q5 X; d0 l8 M& c
     alert("重复密码与登陆密码不相同");       n; l- r+ L3 d" J' D. y5 ^1 [7 E
  document.sform1.password.focus();
1 _7 y: Q2 v, z1 o( s                                document.sform1.password1.focus();     & p) e. r# r3 X: p8 n4 ^* W3 D
  return false;0 R+ ~( R" H" P5 b/ D- b
  } # `/ ]+ F1 u7 K' v
if (document.sform1.email.value == "")     
+ P5 ~: e3 N+ @* T3 @8 |! z" s  {     
" z# ]1 [( ?; C+ x  m# O. `. U  alert("请输入您的E-MAIL地址");     
- A  c5 d0 C5 S- e  document.sform1.email.focus();     
0 j8 [1 d3 z" }: P  return false;     
0 ^6 s) N1 a! S# C: A  }     1 ~5 Q' T3 m, N+ Q% g: K, }  M2 y
      
+ e& `5 z7 @! A email=document.sform1.email.value;      
1 e5 C( A) e# G( l! ~, q emailerr=0     
: O1 O9 ~4 l' Y" @- K/ X for (i=0; i<email.length; i++)     
" O$ V# A  {2 V. K* F5 Q  {     6 f; h1 u5 b; @+ l6 \/ \5 K
  if ((email.charAt(i) == "@") & (email.length > 5))     
4 g& |9 E% i, T0 _& n7 [, p' {   {     
4 u1 J: B6 g# k2 R( F, s     emailerr=emailerr+1     
  C4 |# V8 w$ i+ x) H0 \; B# c   }     + L8 H3 ^! p# K2 c  R1 B, B" b, u0 Y
  }     
' _) a1 k- L- ^' v; j, e& L4 z if (emailerr != 1)     2 o5 C! H0 K" D8 M' W
  {     7 {8 P0 U9 W* L/ N5 D7 d* f
  alert("请输入正确的E-MAIL地址");     ; ^" R7 I! c/ q
  document.sform1.email.focus();     
  Z* G, v. z3 f5 `, r- a0 i  return false;     / ^: {4 F; T0 B; {5 Z. U, K
  }           
2 I( L4 k" \; w! t) R    p7 |9 j1 f2 w( }4 L4 V3 o
if (document.sform1.checkask.value=="") 8 ~. w( `- H5 q: U, Z+ a0 B
  {
; I% ^" j6 x7 `1 y3 z$ C) t* k   alert("密码提示问题不能为空");       h7 [5 ?! l/ ?8 }3 a
   document.sform1.checkask.focus();     6 X9 c+ ^5 i3 j
   return false;  
6 e3 Z3 ^2 |/ R2 ^% G) v  } 5 ?, r2 k$ X0 C+ S
if (document.sform1.checkans.value=="") 8 {+ G2 t6 u1 W' W4 B" g
  { " D* w4 Z" ^/ C+ X
   alert("您的密码提示问题答案不能为空"); / j$ m( Z# ]( Z& ^4 G* f4 a0 a
   document.sform1.checkans.focus();     
' i5 Y; D& r, d/ \   return false;  
/ y4 f  t$ `& H3 d; y/ b  }& ]& C( u1 _) f( q
return true;     
+ f1 S. h, h/ K" c+ D6 U     
. b' A+ U) d$ Z" L}
+ o) M* W' h5 T6 P1 V3 }</script>

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