返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:! c* [' s# k! D
<script language="javascript">     8 {0 m  a8 E! v) C; P4 I8 M4 g5 J/ l
function IsDigit(cCheck)     9 P6 z  L) I, p8 a2 T
{     6 C4 w+ t4 k# Y% g! Y( a# c, f
return (('0'<=cCheck) && (cCheck<='9'));     
0 f3 Q8 g7 h+ W0 C4 a$ |+ l8 U. S }       s" Q. y% C) b$ b
     
" N& q7 ]& q. d4 _7 bfunction IsAlpha(cCheck)     7 M( `7 y# X- ^: @
{     ' K0 S* J! o) s7 Y
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ) y4 n& A8 r% @2 W6 ~$ a. X% W
}                F* Z* [% m* g6 @* j& Y
      9 @+ d5 p) f- M( d% k+ ?
function IsaNull(cCheck)          : d4 M/ n) u3 {" J( Y; \3 q' C
{          0 @- z& Y( K" s
return(cCheck != " ")         - S  f) F' L2 i3 B
}                              
& F) G' u7 K% ~; K/ h& G7 }      " s4 J+ I* I3 _) `- ?
function checkform()     
5 `7 O( y  {/ p{
: ?+ z  `  P5 {/ _& B& A9 x  id = document.sform1.id.value;     ; W8 S" M# j$ s" Z1 A0 t
if (id == "")     
1 r9 }2 a# [  r3 u  M% P* _5 S9 i  {     
3 A& J" o4 F. \  alert("请输入注册名");     
9 X! m. X5 l0 m* n. W( Q8 @  document.sform1.id.focus();     
% T; C  u/ X* k0 r' p' v4 K, ^- t  return false;       v: n. A1 v2 s0 n6 k" `* p
  }     & [; y  A! B" O/ G+ r7 Z
     ( T% t, E9 P/ ]* T$ O6 t
for (nIndex=0; nIndex<id.length; nIndex++)     $ ?' d% C7 M) @( N; O5 `5 n! z
  {     ' O8 A" K8 x! b! v
  cCheck = id.charAt(nIndex);     ) Z# }# G: O4 ]9 \5 c$ D  M# j
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
4 k7 @% F( M' O  }+ l3 Z   {     
, y+ i1 ?/ ~& g' k) W   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ! V' S3 N5 X/ U/ u% J
   document.sform1.id.focus();     % w6 J, s6 [$ y
   return false;     
$ T: ]% ]8 ?2 s' r% ]   }     
5 E* }# L2 O" L6 H  d  }
8 r# R2 ?7 J. y  chineseid = document.sform1.chineseid.value;     
% s7 N" [; G7 b, j if (chineseid == "")     ) \7 s2 u( f" d) J4 E+ r
  {     
6 Y8 E/ r* z4 ]. A+ x  alert("请输入中文昵称");     
% _$ ]# C0 ^- H6 @4 t, b  document.sform1.chineseid.focus();     2 H2 ^+ p2 Z1 G6 j0 ?
  return false;     3 A! X6 n3 a7 D+ W6 w5 J/ u
  }    2 d! T, \8 r1 L+ C5 D0 ?% f' O9 t+ i
password = document.sform1.password.value;     5 _  K3 y. P0 c6 G5 A
if (password == "")     
" \4 G; _6 j# _/ p3 H  {     
: j' u' N4 P! ?1 S7 q( v8 }, I  alert("请输入登陆密码");     
" E0 Z; \6 w4 n; e, @  document.sform1.password.focus();     # x# m" w; R; p4 m) |
  return false;     
% J2 L/ G4 h0 q4 b& h  }
" p3 v( N5 Q( H$ S password1 = document.sform1.password1.value;     ( j3 a1 A- g" @# y! e$ i' X6 @
if (password>password1)     
/ a; r2 v  {$ A7 {+ S  {
6 O  s$ ^# j4 J' k6 z# I. Y# I     alert("重复密码与登陆密码不相同");     0 k4 G* W$ w( G4 R- V1 J3 x
  document.sform1.password.focus();
1 S8 ~9 ~4 ~- D; X! Y                                document.sform1.password1.focus();     
2 `( Y. V, c0 u/ x8 }) {  return false;
) {2 Q4 d% H% B: w/ a; z" N$ P  }  $ T1 D6 q6 H& t5 ^; p
if (password<password1)     + D* v' O# c6 o+ j
  {
. x6 G: z) f0 m" D, \9 E     alert("重复密码与登陆密码不相同");     6 ^) l$ F! \7 |) Z) O& f, E
  document.sform1.password.focus();
8 s( e9 V( W/ [: v  C* H                                document.sform1.password1.focus();     
1 R! s( j! f; W  return false;- Z- M) e4 I2 x' s. n; t7 m
  } " o+ |& m) g2 o9 R, {0 d
if (document.sform1.email.value == "")     
" x! B- N) I; R. H  {     & A5 K$ S# p% X
  alert("请输入您的E-MAIL地址");     - E) U5 z( I" b1 H# a
  document.sform1.email.focus();     
+ J' ]4 Z. u  X" k6 j3 W  return false;     + i% o4 E6 X5 X/ ?
  }     $ k& b# ?! {; P1 C
      9 S5 w. }0 H. V4 J8 }
email=document.sform1.email.value;      5 I0 I: @" `  G9 M, @5 p
emailerr=0     
5 x7 b. g- u& P  O$ @6 q/ u7 i for (i=0; i<email.length; i++)     
2 o+ W+ i" F8 n* c" }# U  {     
$ K9 n& g# s" o, q2 J  if ((email.charAt(i) == "@") & (email.length > 5))     
5 E* e: G) [3 j# t0 t" W6 l1 h8 R   {     4 @( K, c( K4 a$ o9 l+ }6 i
     emailerr=emailerr+1     
* @9 j5 A. @: ?* ?: @% H+ V   }     
3 c/ {' M1 R% a  }     
1 O9 A# r9 Z0 V- c2 c6 E if (emailerr != 1)     - F: J% k( t$ N
  {     
6 M: w/ u8 y5 Z5 [- T  alert("请输入正确的E-MAIL地址");     . C' x& }+ V! S
  document.sform1.email.focus();     % X; `* T5 }: F. i( G
  return false;     7 X2 ]& J& w+ d( n* V# f4 @
  }           
0 f$ l1 E2 W+ H1 k% k  
; m) L- e9 r" _# H2 w( h if (document.sform1.checkask.value=="")
; n1 Q/ {1 i( ?- @0 u/ t  { * t7 `2 J1 g. @9 t
   alert("密码提示问题不能为空");     
- }8 e/ \0 \& [) Y% g: x# Y9 W   document.sform1.checkask.focus();     
+ `6 w& H* n3 K8 w3 n+ K8 y   return false;  ) Q( f* h3 m$ J" G/ m
  }
5 @. G4 m6 v8 {4 ~8 m, ~ if (document.sform1.checkans.value=="")
" y6 A8 E) E) h  {
3 I$ n: A/ P3 r3 ^1 {- `' F1 G' r2 T   alert("您的密码提示问题答案不能为空");
- E, T' V& c" Q/ |6 w   document.sform1.checkans.focus();     
' A0 N0 M+ U1 x2 P; ^& d   return false;  $ ]' k3 X" [& Z1 r+ v
  }7 d! X; j# o1 `1 C* x' g4 }
return true;     7 U( f& H7 v. w, ~8 `! p
     % ]6 F7 P8 I3 I1 C; S/ E
}
0 p/ w9 S, Z) d$ x* ^1 ?</script>

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