返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:1 w$ q/ A, k  F) E: h' u; y
<script language="javascript">     # a$ o$ b1 Y' |/ r
function IsDigit(cCheck)     + t3 \! I. v- ]7 O8 r$ U
{     
3 X8 q) B7 K9 \' I, R$ N+ r return (('0'<=cCheck) && (cCheck<='9'));     
' e1 g2 }! G' C0 q4 c }     $ V/ P4 g  d, G
     
: x! }- W' ~5 Yfunction IsAlpha(cCheck)     
; r, C9 y( V/ w: z" U7 [& u: d {     ! l: ?+ t: k& c$ A- U
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     " U# K2 J9 h4 J* E+ H. f7 M
}              
9 v* {. ~" ?: i& \      
1 P/ |6 o5 y; M$ W6 afunction IsaNull(cCheck)         
3 b' P5 I0 l1 w/ [: U7 B" Q {         
) W2 Q( t6 |/ G7 |4 f; y, s return(cCheck != " ")         7 D7 i& Q' `8 ~5 ?1 g9 V# j
}                               $ e2 T1 }7 w* d3 \3 e1 E% {
      , `& r/ V% Y: V* f. n6 |' R
function checkform()     # ]2 T& Z2 s! Z# h" C
{ ' y/ t' q, v" w5 a% A! K; G& E
  id = document.sform1.id.value;     
, M+ l0 a" R, K if (id == "")     % E# }" U, k) w# u- Q2 |; x
  {     $ b+ [4 L4 u0 k6 R! ^4 l
  alert("请输入注册名");     
( o  \$ J6 t# h1 o& d( n6 w  document.sform1.id.focus();     
0 m! }* {. }* U5 F  return false;       \$ B4 m8 U) z7 [7 t7 l
  }     5 @. F7 g+ F7 |/ Y
     
$ i# [( _/ C7 _  A. T+ j for (nIndex=0; nIndex<id.length; nIndex++)     
% r  F& s) K$ o" z* N) V; k  {     
2 k6 k; I  U5 |# [' d; R. _  cCheck = id.charAt(nIndex);     
5 Q+ ~8 }) _/ g) Z5 G3 x  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
8 u0 _, L/ |) s$ m" H, T   {     4 k8 y8 Z, T$ M& m" ?
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
2 x6 S2 _, _7 C8 U) B   document.sform1.id.focus();     
4 p1 X/ I* R+ s" p6 J4 o" o   return false;     
: s) F) _& e# w5 z5 [   }     , j5 ^4 @! `6 J
  }
0 l6 w6 L: J6 ~0 j  chineseid = document.sform1.chineseid.value;     
% F3 m$ g$ u8 T3 X# f if (chineseid == "")     ) G& C9 r) ^* P" F
  {     + d: `, r8 h% W& C0 s+ P, ?
  alert("请输入中文昵称");     $ u, I+ k; x$ f: ^' n4 ]
  document.sform1.chineseid.focus();     
7 C+ ]$ q2 ]. L6 c5 U; \" a+ S9 {  return false;     - Z" J: ~: H3 W1 l: f9 Y( i# Q0 u3 H
  }   
2 o6 p- W# v( N- S password = document.sform1.password.value;     
9 W7 y" f( a" D if (password == "")     8 T9 U" G* }4 n2 z9 d
  {     
0 W( {0 k6 M- ?' \1 Z7 D  alert("请输入登陆密码");     ) @' V$ R5 `* z; d0 h; |0 C
  document.sform1.password.focus();     + r$ a  K# G$ L4 @8 v2 A8 M5 A6 L
  return false;     / K! \/ z4 X: p  o) `! {4 i
  } - H, a# V+ f% b; S  p
password1 = document.sform1.password1.value;     
$ \: P% d5 j$ V$ A% J& Q( ` if (password>password1)     
' S  K' S& |3 {, W( L* i* ?  {" ?) V% E# i% L  l" m
     alert("重复密码与登陆密码不相同");     
' P% i8 o% u+ ^* i8 ?0 q  document.sform1.password.focus();
# i, Z5 d" Y- ^1 {                                document.sform1.password1.focus();     
; ?8 _0 o! d$ c. ^  return false;
2 O) t! k, g. w% H( h' B6 x  }  ' s& u/ T. M' j/ _) s2 t
if (password<password1)     
: D' X5 p6 d% M9 G/ \  E1 r; x; ?6 R& A% d  {$ j' I; g" h+ N
     alert("重复密码与登陆密码不相同");     
1 o* W) H4 q7 G$ Z  x) ?8 P4 [7 ?  document.sform1.password.focus(); 4 ^8 b7 O8 J( t1 o; A/ f: F9 p2 l
                                document.sform1.password1.focus();     : l' ~; `5 {) N* r  q: j2 b
  return false;) v, _: w6 f/ q6 z& U& m
  } 1 j( v3 S4 [5 p8 N
if (document.sform1.email.value == "")     
8 t0 R& j1 [! F: R; ]2 o: v  {     
! Y1 X% q5 \& o9 m  alert("请输入您的E-MAIL地址");     
, W6 c9 H/ A) l- I$ T' q  document.sform1.email.focus();     
( f" V8 \8 z1 {5 E& ^  return false;     
* p9 G2 n$ D1 h  }     $ j/ a. i1 @9 }# S$ K
      + l' X2 [  G6 x; p1 a! b/ x
email=document.sform1.email.value;      
' ]* y7 Z$ m4 x4 o' L emailerr=0     + |) N9 c& a2 }+ `+ U. F  p- X
for (i=0; i<email.length; i++)     
' r; v% P. L* s5 Q  b( M  {     5 a" ^4 |& ?) R
  if ((email.charAt(i) == "@") & (email.length > 5))     
+ e% S5 M4 t# E0 U; \" d   {       b; r  d! z0 N$ W! H3 c5 L
     emailerr=emailerr+1     
% |6 n9 [  y0 j+ T7 T   }     
" C: u8 |3 f$ w  }     ! H4 {7 n5 e$ b- k  S  E
if (emailerr != 1)     
7 i8 Q8 z! |4 H  {     9 p" I& E/ [% y/ K
  alert("请输入正确的E-MAIL地址");     # r+ d) |# }0 S
  document.sform1.email.focus();     1 V2 ?% z& P% F3 U
  return false;       h* D' Y) _( [9 W2 G! ]
  }           
  C. {3 q% _( j8 a* M  
& E$ c2 ?% j. X5 E  I3 n6 s+ Q8 G& u; W if (document.sform1.checkask.value=="")
+ ~3 ]$ r7 z4 o$ p- @+ R- y' N+ Z  { ! r  q% l* _$ P* n- C9 b
   alert("密码提示问题不能为空");     # l2 a8 R  P& n9 z3 Z
   document.sform1.checkask.focus();     
) h( Z  I* S' J9 O3 I   return false;  0 P7 i  ^- u! {5 A. K
  }
2 ^* C/ z* g3 n0 F, w" c% t1 x# | if (document.sform1.checkans.value=="")
4 R7 e" v& c5 L5 d  E  { " Z) D+ I) d8 Q0 D: ~: c
   alert("您的密码提示问题答案不能为空");
% w( ]- X5 @0 q/ ]9 m3 q   document.sform1.checkans.focus();     * k( K  H( L3 w3 ^
   return false;  1 b' j8 t* K, O6 J- S6 {# T3 @/ K
  }
' t+ g$ ^, s! M3 I5 P return true;     . H8 S" V* n/ f) _1 N, k
     
: @5 @* ]  m( S& x+ \5 f# H. {}
; a( W- T2 D9 R</script>

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