获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
0 I& a9 }) c) f2 `<script language="javascript">     ! n; _" j. u* X
function IsDigit(cCheck)     
) c1 {& J. G' \  Y& Z {     ( t7 k" @1 O  d. f1 F. s' w; E
return (('0'<=cCheck) && (cCheck<='9'));     . T& E9 Z0 k- A7 P4 t, g
}     
/ w% D( A( e4 J4 ]2 Q     
8 i: b8 R( y9 f; Sfunction IsAlpha(cCheck)     # q8 z8 F: D9 J# m; e1 Z& y
{     4 g7 v% K. V" @' {3 C, l
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
' {6 @4 [/ `# F7 g$ k$ i }              
# r: n& e# U( W( X      5 x8 [5 e# u4 q
function IsaNull(cCheck)          # ]/ i, t  I+ w& T0 [
{         
) k- G4 {% o1 _, k1 [2 i/ G return(cCheck != " ")         
0 z7 ?. S, o' n& _* s }                               4 f# o1 w( Y# p: E
      
7 q% Z: J3 q3 B( i" o9 }* J( J( |4 _function checkform()     
  g) Q8 ~; Q* t9 G0 [* b  H{
! S1 P/ d3 U& F1 c" a  id = document.sform1.id.value;     ! Y3 h& Q9 L% @& i9 T1 J
if (id == "")     6 g# X$ Q. `- A0 O- R5 |- S
  {     
. b' ?# R+ G3 t! o4 z* r  alert("请输入注册名");     * ^; B8 g% V; |
  document.sform1.id.focus();     
2 `. e0 E9 c% C3 p  return false;     
9 b5 y: [1 w- U( X8 j$ O% Y/ a  }     
: c8 s; x% f1 h$ L9 `, _9 _     
( H- V$ ?- p& e& c$ P for (nIndex=0; nIndex<id.length; nIndex++)     
1 H5 t4 P1 q4 @# D  {     
) U% n5 E& u( _# L' ?  cCheck = id.charAt(nIndex);     
. r( O. s0 y* U0 m2 E! M0 s  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
4 d" @6 v+ W/ s) A   {     $ X' y9 x' f1 B7 V, k6 ~7 I* n4 ~, o
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
! H; I% [3 ^3 _$ K   document.sform1.id.focus();     
' M) m- c: L2 u" C! Q   return false;     - K& P3 c- ^! Q7 n9 P8 ]
   }     ( N1 o7 c) p: ~/ d( k8 ~( x
  } 9 ]8 O- s6 a. p$ @7 B5 Q
  chineseid = document.sform1.chineseid.value;     
; v/ |' V! H/ M' i4 P" _ if (chineseid == "")     
3 l- r: p( |9 z; s) U  {     
9 C% X" _6 H% ~. ^, L( P. D  alert("请输入中文昵称");     
  K0 d3 Q5 [$ p" I' O) A! O2 p, M  document.sform1.chineseid.focus();     
* U, z) y3 ]- g8 Q  return false;     
8 R3 \' O! m' L. S% b/ V  }   
4 g; t3 o. t4 w3 a: `, } password = document.sform1.password.value;     " f( x/ m) k$ l3 d* ], l
if (password == "")     
8 n5 i7 ?+ z# W& d  {     " v# P& D) t) \# I3 I
  alert("请输入登陆密码");     
0 U# H. ?+ G& q. Y8 O' ?  document.sform1.password.focus();     3 N" |6 Z2 g. A7 y
  return false;     
  D* e0 z& s2 O$ z  } % q, W  h/ o, u) T9 J/ f# k3 t
password1 = document.sform1.password1.value;     ) l' v* R, M+ W5 _, x; C( c" O( ^7 z
if (password>password1)     
" k. S. L+ G: p$ `4 r7 c; |6 T* J$ U  {
. x* h' V, M6 a( C     alert("重复密码与登陆密码不相同");     # y! j1 o) E: _/ B
  document.sform1.password.focus(); 3 D7 S* E! v! M$ `; C) G1 E
                                document.sform1.password1.focus();     , n& \( R5 o/ T& t
  return false;- v! j1 Z5 i8 D) b; F; [0 s4 n
  }  2 V+ B+ G/ Z# x7 ?$ R$ j9 b6 w
if (password<password1)     $ t8 b) f# F( [. w4 F3 `3 C3 L
  {
& ]6 d5 P. t  O. o     alert("重复密码与登陆密码不相同");     
1 k4 W; L2 O1 U9 L  document.sform1.password.focus();
" x; `5 }9 u8 D! L" o( q, H                                document.sform1.password1.focus();     & s+ W8 }/ j2 @9 w
  return false;) ]7 X7 _* }0 }, t' W
  } ! H$ q7 \" w- m, u- q$ j6 L
if (document.sform1.email.value == "")     
( w- ^  G; ~$ b7 ?+ j. V  {     
. Y7 w& `) Q/ D; s  alert("请输入您的E-MAIL地址");     
/ F4 `2 M, l% E5 N4 @& I( _/ y  document.sform1.email.focus();     
' c3 i9 p- t$ z" p9 R% M  return false;     
  W# V# p3 ^: g! m" }  }     
) r0 X. j/ l+ z3 y5 h# a9 V      ' v( r" P) C: W) [2 ~
email=document.sform1.email.value;      6 f" Y# G3 k% Q
emailerr=0     2 B4 k& j4 e3 u
for (i=0; i<email.length; i++)     . R6 L+ t+ L! F& d" @& T( d
  {     
$ ~# T$ K/ f$ K. q: n' o2 F  if ((email.charAt(i) == "@") & (email.length > 5))     0 D3 y; R. {* b0 u+ U
   {     
9 z. b7 s+ f( F* \     emailerr=emailerr+1       \- _& L4 Y* N8 Z
   }     
$ g& ^& S/ r. s" r. n) d! k  }     # _, m: B+ M$ N
if (emailerr != 1)     
$ g& Y0 [8 T4 e& |  {     
4 H( `8 N% a" Y  alert("请输入正确的E-MAIL地址");     0 f4 U7 [) K; k( P6 ^% A
  document.sform1.email.focus();     ; A- h3 V) @2 K, _- v
  return false;     
. X! T! A6 S# F& y9 @5 z  }           0 V" Q9 a: \& h3 Q/ m
  % J' N0 X# |6 S4 G
if (document.sform1.checkask.value=="")
( w: w/ e; t7 W- d  {
$ h: C5 `* b9 ^1 G   alert("密码提示问题不能为空");     7 R5 c# E9 X) N
   document.sform1.checkask.focus();     
. S% O( z* r$ n   return false;  / b3 @3 K" i  I# x! y& j' x
  }
/ f8 \! u/ `' O2 Q if (document.sform1.checkans.value=="") % w) [  K$ s, P% t. m
  { 7 H5 t, A3 |0 p) ]/ n; ^
   alert("您的密码提示问题答案不能为空"); 8 C* t, M1 |( s% S1 G
   document.sform1.checkans.focus();     
0 \$ h+ M! \( R; T( `" _   return false;  2 z) ]1 z9 U2 D  p0 m, H3 h( ^
  }
& h8 C, O5 V2 Q$ F- t& |! r return true;     
' U/ d  F+ _& u" n0 V4 B" }     5 F/ b4 m6 w8 F/ d- G; M
}
% A7 z  e" z2 q* s) R* N</script>

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