返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:/ p1 @5 _. t: r/ u, }2 ^
<script language="javascript">     
- h& t: \1 q! C4 o$ N+ ~; Y  Rfunction IsDigit(cCheck)     3 O, B# \  L: H: l
{     
; s; j3 s5 y5 D8 Z: c return (('0'<=cCheck) && (cCheck<='9'));     
0 b+ S( ~. p1 s* x. X4 Y }     ( |- t! H1 {$ H- m
     
3 }; L' l; R9 xfunction IsAlpha(cCheck)     
2 u! O* O% y% L& z4 ?$ s {     : ?8 b6 A6 k) x, ?
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     5 X" G3 y& `- S
}              
1 W; O! i& [; g/ w6 s  {      ' ]4 x1 m3 @  Y0 Y5 N% B
function IsaNull(cCheck)         
( i! m/ E) s. U) S* v  U& C0 Y/ O {         
6 `+ O8 G' G! Y& S" U, h0 @8 ^ return(cCheck != " ")         $ H% H% M" g  W
}                               # w2 K# E) U7 @5 J3 ^
      ( E! f5 S9 i% v" K7 |
function checkform()     
2 F5 T5 R$ K0 d& l+ f% Z{
& T# n0 ^( F( D% x2 k  id = document.sform1.id.value;     ( f: N& W) ]8 E
if (id == "")     7 a: \( p; h* |1 Q, g7 @4 {& z
  {     ! S1 v3 \3 J# |7 B
  alert("请输入注册名");     & u) F" R/ I4 f& C8 ]7 X4 G9 _+ a
  document.sform1.id.focus();     
* R6 Q) [* h. ?* m( J! V% L  return false;     
5 P6 q( Y: l4 a/ ^' ]+ W7 }  }     
4 K2 g. ~7 c3 \8 y6 c- P, A% U! ^     
2 x8 V9 r. U7 N2 ], y  L for (nIndex=0; nIndex<id.length; nIndex++)     
# E/ \5 N% F. @, k$ o% ?  {     ) A, Z" Q3 [. W3 j* Q3 ^6 b% \
  cCheck = id.charAt(nIndex);     5 [+ P7 k& ]4 @. P
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     4 l7 l" R% M, A5 y( G) k1 N0 K
   {     
  C# V* H% L1 T) a! P   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     7 g' B5 t8 u4 ~1 S" Y! k, e* A
   document.sform1.id.focus();     5 d+ R" e" ?) ^! X
   return false;     
. L  N! R8 Z9 \" }4 _- N7 s   }     3 u% ]: r. K& d) P* B
  } 3 \  `7 R3 g' K" P3 p
  chineseid = document.sform1.chineseid.value;     
" R2 q  d0 v( f( a if (chineseid == "")     
# P. F5 b% X! N. o; Q" u* v; v+ V9 r  {     & b7 p0 i1 e9 M! U
  alert("请输入中文昵称");     
  Z6 r; _+ i+ s0 J/ U) U4 ~- X  document.sform1.chineseid.focus();     # ^, e( D$ V& O5 D. `
  return false;     
0 \( s3 T- t; K$ |% L7 V, U# D  }   
5 j. `& R; n! u# I password = document.sform1.password.value;     / g, C, ~# _( t  E% B
if (password == "")     
0 c6 @  Y1 u( b  {     ! t% ~% y5 h2 F8 H8 K% E
  alert("请输入登陆密码");     7 V2 R; z1 m: t. J0 Y
  document.sform1.password.focus();     6 n8 q1 z, u7 r! ]
  return false;     
9 j* Z- W  X. ~0 T0 F1 J  } . `6 B" M3 ]( W5 T" u+ f
password1 = document.sform1.password1.value;     ! W9 \; E! f  O2 |; @
if (password>password1)     
. k9 L) K7 v, y' @- E2 x4 m  {8 t+ p& p% K# P$ N/ l: A$ r2 o
     alert("重复密码与登陆密码不相同");     
) O: G( T/ }/ F% Q. F  document.sform1.password.focus(); 5 `! q8 l; N' `1 o" H0 w5 Q9 j8 r
                                document.sform1.password1.focus();     
% p& B" W; [& w6 c0 ]) _4 w  return false;
9 `' y* a) Y, n+ [+ `* R  }  
  }# J+ P% X7 I$ |" V! `9 Sif (password<password1)     ( Y: W" b% R- K
  {* T" }% l& a& |6 B1 F
     alert("重复密码与登陆密码不相同");     
- `% @+ r  U- m! z/ F  document.sform1.password.focus(); 1 T4 l& [% `/ P6 ^; I; D8 e: ~
                                document.sform1.password1.focus();     
3 ]2 M) I* ^1 X& o, K  return false;# y' H3 |$ o; ^( ], {/ j6 k1 c. o
  } * p1 J8 o: u6 u. U
if (document.sform1.email.value == "")     
. ?2 H' F  K4 p, J  y) ?4 @; {: s  {     
) ~4 H  q0 [2 D7 e& O* I  alert("请输入您的E-MAIL地址");     3 I( G% ~1 M& ~- y
  document.sform1.email.focus();     
" D2 ^1 W  G4 w  x( |- P/ @  return false;     
$ c1 x7 {( a# {2 J4 S( m6 @: ^  }     $ d/ D  P) C* \* U. n
      
! I( A1 U9 l3 w" S" M email=document.sform1.email.value;      
% ^/ z7 v: \3 B1 H emailerr=0     5 W+ h! N% d* R, G# u: Z1 ?
for (i=0; i<email.length; i++)     % w2 @+ ]% f3 p8 f
  {     7 u" M' G; q7 n3 n) Z- s0 _! D# N/ R
  if ((email.charAt(i) == "@") & (email.length > 5))     
4 Y1 r/ i3 f# f. I( j- t   {     
, l5 S) y, O+ e+ [     emailerr=emailerr+1     
8 L& V. Y5 A" L1 c8 m4 K( M5 P   }     
5 E4 v2 s: f$ }1 Q  }     
& R7 ?. N5 R: s5 R* D, n9 e if (emailerr != 1)     
/ U# S: I" O$ b1 N8 T% I  {     4 K8 u* ?3 ?# |
  alert("请输入正确的E-MAIL地址");     , j6 x8 f2 m4 i4 X0 `
  document.sform1.email.focus();     
% e6 q6 f4 P) v1 ?) G4 ?" M  ~  return false;     . ~: R0 o, @6 Q% M
  }           4 M% O3 M9 ^/ c' z
  8 N) C3 v) V# |5 ?2 Q5 Q/ X+ z# ^
if (document.sform1.checkask.value=="") / x! C: Y5 q" z' U
  { 6 [3 c% u, d6 g7 O6 K
   alert("密码提示问题不能为空");     " z! u! l3 I" d' d
   document.sform1.checkask.focus();     5 S, a( g$ _+ [0 Z2 }( I
   return false;  
$ z# l; _; K, e  } 0 T: M" P2 n8 w9 M
if (document.sform1.checkans.value=="") % u1 N2 l+ t4 O, H) a+ U4 x; }) q* V; g
  { " ?, ^& X3 e  V% ^
   alert("您的密码提示问题答案不能为空"); + {& G. |' v2 |! ]  L8 y& @7 h2 X
   document.sform1.checkans.focus();     ; Z& d$ V+ C" ]" U( h- e
   return false;  
& a% d# h" ~3 G/ g6 r# L$ u8 G  }
9 u" _  {' Z2 F$ A# Q2 r return true;     , I8 ~$ M9 e( R* A' g$ d
     ( s# ~4 s5 k( Q$ n
}
$ Y5 ?: W) t9 G, \: t</script>

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