返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:! Y! M/ I: c9 o4 i
<script language="javascript">     
# c6 g. U* ~: ~% v) x: ?  ?/ Ofunction IsDigit(cCheck)     
% Q6 B; ?; f, W7 @ {     
( v' ^8 m; }% M4 Z  P+ m return (('0'<=cCheck) && (cCheck<='9'));     $ S* Z/ c7 E: s3 J" h5 {+ l
}     
5 c6 G& w( B/ E4 X% J# n4 w     
/ }, `, q5 J8 l6 ]0 w, `# Jfunction IsAlpha(cCheck)     
) k# Z' ^$ V! W& r$ E* u7 d {     
6 @% @+ A9 d6 M$ N1 n return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     " g+ S1 r( O  s! b3 r( ~9 y4 L
}              : @/ Q( E7 J) b' Q- E0 ]2 f
      % C) L8 }; y# H  r2 b! ]
function IsaNull(cCheck)          . U8 U0 n2 k  A" x; i
{          $ u  [& c' H; T; h. j
return(cCheck != " ")         
; R) L: V( R' u }                               # s5 G0 T4 |7 u, ^+ ^
      7 |: M4 @! G  A) i2 j' S
function checkform()     + G! T  P% Y7 u- @: A% ~8 X
{ 3 l  _5 w, \" n% j& o# d
  id = document.sform1.id.value;     
$ K$ J0 ], J) Z: o8 j& b; h if (id == "")     
( w' d8 x: k* N# [; j7 m4 Y, f  {     5 ]& S  g+ Y! T7 c" ^. z
  alert("请输入注册名");     # r! @$ O7 a! `0 L- H1 d2 X
  document.sform1.id.focus();     4 d5 s( T% U6 F  p" E
  return false;     
& x$ @0 l% ?) K4 n: a0 P  }     
9 n* G- r! T) V+ n& Y     " A3 R0 d! @  w& L% _
for (nIndex=0; nIndex<id.length; nIndex++)     
  M! S' @, X% t! p& B  {     " }" i/ i9 @$ e3 M  g% T# X2 D
  cCheck = id.charAt(nIndex);     
& B4 t+ O; ]* @& K) b1 `5 O# w1 ^  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
# m: x9 Y8 J3 L5 X; a   {       t) F3 X0 Z  e8 S
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
4 y1 h& B: \3 l4 R* ?   document.sform1.id.focus();     
( o$ y. H# `: P3 F   return false;     1 l# A# _' X* C, i
   }     
, T  ^9 t! O8 }4 J& d  } 4 X/ q7 j, g( B3 ^
  chineseid = document.sform1.chineseid.value;     * v' q* C2 l/ P. Q" N% ~' M, a3 E4 ]
if (chineseid == "")     " P: Q7 J+ R2 D  Y  `0 z
  {     
# L; E! ?  V5 o+ p  alert("请输入中文昵称");     + n( L$ E$ E' K
  document.sform1.chineseid.focus();     
0 f  }2 s$ o8 M1 Q8 D1 y  y8 j  return false;     
7 P8 n6 W/ o9 M  p7 K  }    8 X! Y3 m  [% Z, \
password = document.sform1.password.value;     ' U( I" J, E; k/ T3 |$ h
if (password == "")     
6 ?- j1 H- t& A' o. I' Z$ T  {     - S. _% ~: F) h
  alert("请输入登陆密码");     1 I' T) u& r# f6 Y9 p( F; b
  document.sform1.password.focus();     
+ z& H% c' Q+ Z6 l- A  return false;     
  y% G' h. W0 j  } ! f1 v2 `0 P/ L7 s. J$ p" j
password1 = document.sform1.password1.value;     
, ]# ?' e* H6 b6 j/ @! ?; F! d if (password>password1)     
( b& P' v+ z, X; G3 o  {
' b" o" v: [: L# r4 L& V     alert("重复密码与登陆密码不相同");     3 A2 ^7 C8 C5 ^2 Q
  document.sform1.password.focus(); " T! T- s$ a+ `, T) }4 Q" |& _
                                document.sform1.password1.focus();     
! m$ G1 ^' l& _' ~9 I8 t7 N  return false;
/ [* A2 e* x& T# N3 Q4 V: W  }  $ I' h) U0 g& Y6 M5 ~) u$ s
if (password<password1)     & Q! c8 R! X+ N5 m# ^
  {2 `! _) T; U  C
     alert("重复密码与登陆密码不相同");     $ g" G4 i+ Q1 K8 D, E- D. `7 p
  document.sform1.password.focus();
; H' H; e7 S* N: e2 m" t6 C9 n2 j                                document.sform1.password1.focus();       V. g' Y1 \8 y+ G' h4 l/ N
  return false;
) n2 |& ^+ m( i  }
* ~  ~' l/ Y! S0 C if (document.sform1.email.value == "")     8 Z/ \: f4 a9 T" F, {8 `
  {     , \: f2 N& l! \
  alert("请输入您的E-MAIL地址");     . Q5 }1 m0 R/ h4 I: J2 A
  document.sform1.email.focus();     6 s1 ]" {+ {$ Z7 u
  return false;     
) k7 |9 V! z9 C: V0 F( d  }     7 E, G/ g  X. b: e$ q3 ?7 B" q
      & ^& n& e8 ^) y9 J/ N% D0 Q; ~' L: b
email=document.sform1.email.value;      0 ?- Z: ~$ f& p' R& ~) ~, L+ s, p) [
emailerr=0     
2 \5 Z- q5 l& d0 K5 P  ~ for (i=0; i<email.length; i++)     , h6 t$ e" T; d4 N& o) Z
  {     6 E3 B# B6 u, K1 j) S
  if ((email.charAt(i) == "@") & (email.length > 5))     
; d8 A+ X7 z& b1 L0 T" i; y1 N   {     4 C4 a$ Z- t* o/ z, j2 k( D
     emailerr=emailerr+1     
% Q2 u/ t0 C9 N. k1 L   }     / z% n' k2 L- w; f, W& r4 v* X
  }     8 L) ?: F3 t) |! o' ?) R- ]
if (emailerr != 1)     
1 w% v( `& D3 ?4 j  {     
" F/ f' p8 t; _2 i) `5 v1 ]3 G9 y  alert("请输入正确的E-MAIL地址");     
( t) v: K* V0 B4 i/ C  document.sform1.email.focus();     - x( R( i: R5 L
  return false;     3 S/ h  s$ ~3 Y3 A$ }5 J
  }           
8 r, K; R1 N9 |  b  
# @! c  n1 i* l! C& d if (document.sform1.checkask.value=="") $ Z7 Y0 m' N: U& g' T3 G
  {
9 K0 T1 U7 n) D' H, J9 q$ `' k" i   alert("密码提示问题不能为空");     
8 r: M" m# I1 U0 f: f   document.sform1.checkask.focus();     
5 m3 ^; B" F5 j% N% E9 o' J# b( m) J   return false;  
& Z5 g" L9 P3 W2 x  }
# X0 [1 @4 n1 Y6 W5 H  a4 b if (document.sform1.checkans.value=="")
( T6 \1 `' z) M! _: X* p  {
$ }9 f) L: M( B6 S1 f   alert("您的密码提示问题答案不能为空");
. n; }, F! z/ u   document.sform1.checkans.focus();     
7 k  i: x' v9 e' _8 d. L  c   return false;  5 ~/ H8 a2 m$ j6 ^" U3 }
  }
$ r8 I- M+ i& x/ Y' g: N/ e# V& @ return true;     
/ k7 c0 m3 ^- r  \- _' V     - B! H) w: ~) d. `- o2 g, E
} ( |! @1 l6 u; H1 s$ S3 ^
</script>

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