返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
5 A& e% p' V, X/ Y& e$ d) R<script language="javascript">     2 @7 L2 _( ]7 ?' Y" U
function IsDigit(cCheck)       Y4 \' _/ h$ j- ^# t8 i( C
{     
% X! V7 F6 |* C& D. i return (('0'<=cCheck) && (cCheck<='9'));     
  }7 C$ W) p9 J' q( n }     
8 O, g# n# \6 |% Z" z     
6 g1 t, a8 [) \9 Cfunction IsAlpha(cCheck)     
6 S9 b2 K$ u/ B& j$ \3 [6 ^ {     
0 G( V6 g5 l& b" ~) g return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     : y; V% ?. E4 O5 ^1 C9 s* e/ F
}              % k; O6 }+ k9 o2 f0 o% N2 G
      
- j) p3 r4 J4 {! ^! efunction IsaNull(cCheck)          6 x# Y3 u5 [6 X4 l& v6 l/ W3 ^, T
{          - Z1 A+ Q# }& t) b
return(cCheck != " ")         $ R# d2 N9 C  [% q! ?
}                               ) p7 H5 q6 E" F7 @$ e
      
' D( S5 ^4 y4 ^! Xfunction checkform()     0 x* t/ M9 d( M* \' B; v2 V
{ # c& c& B+ G& s# ^$ I! o
  id = document.sform1.id.value;     " J% \) S( P+ Z9 j7 z
if (id == "")     " u6 n6 `3 x; y; u
  {     0 d4 O6 t" o+ ]$ i+ j0 l
  alert("请输入注册名");     / _4 y) i+ x  O' h! W
  document.sform1.id.focus();     - S2 }$ t& i+ [8 f4 P# h9 t
  return false;     
3 a( z2 z3 x5 Z/ J* v  }     4 w7 E. F4 W1 Q! p8 w! X3 p& F2 w4 c
     # z: F7 P1 J* p3 C" V& c& \
for (nIndex=0; nIndex<id.length; nIndex++)     
3 K+ u( K! l6 b4 S1 F; c( y  {     
& y; U  I% L6 ]( f- }. x  cCheck = id.charAt(nIndex);     $ y5 B1 a1 y8 x9 h# f5 T4 K
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     1 W4 `) U  `7 [( G
   {     
6 l! H. g( z) o- O2 n   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
. x" }8 H5 z* [3 ?4 W- |+ `   document.sform1.id.focus();     
7 s, ^0 Y1 @" C/ @. j) ]1 k" ]   return false;     
  o- B/ A* c& Q* M3 C- A   }     
7 P  F+ M' d. _: j+ {  b& u7 O  }
" k3 |: w5 _+ U* X  chineseid = document.sform1.chineseid.value;     2 i1 l" [* x+ K9 L
if (chineseid == "")     
8 p8 F/ m. w" c: l  _8 `9 w( P  {     5 `" ^0 l2 I2 W9 a  S' N1 `% v
  alert("请输入中文昵称");     * C) b7 C" T. H. \" o
  document.sform1.chineseid.focus();     ) V/ b9 f/ W% L: }$ U& L: _* g
  return false;     / g3 F% E" r3 `
  }    8 ^/ w" p1 Q8 V
password = document.sform1.password.value;     
, J5 ?, H0 C, ]9 }+ c if (password == "")     - R& ~9 h* s- U4 Y3 p
  {     1 ~5 X* Q' [8 D
  alert("请输入登陆密码");     4 m2 G3 B! O2 X, a. d- Z0 R
  document.sform1.password.focus();     
( h2 [. l: K; R  return false;     3 z& L) U7 p  u) ~4 q; Y
  }
. i: m9 V% W9 m& U0 a password1 = document.sform1.password1.value;     
6 e. J. G- ~3 c0 L& Q) Y! L8 U" t' h if (password>password1)     % r7 C/ H! R; y+ P* K
  {
4 R( f6 }, l" w9 J     alert("重复密码与登陆密码不相同");     
5 x/ U+ R$ X% f  document.sform1.password.focus();
1 e7 G1 q" ^3 }+ |* L                                document.sform1.password1.focus();     
- u. F# p- |" H( u# Y$ D  return false;
6 ?/ a" m5 M5 x  }  % l9 ~$ b( x7 z: M
if (password<password1)     * b; j. y: ^. @# c5 T
  {
% F1 R0 A6 I+ u) x# v' y     alert("重复密码与登陆密码不相同");     8 y; P1 y. V8 U7 m" _4 d; L
  document.sform1.password.focus(); , w7 }3 i4 r6 P/ q! L% K7 Z: i
                                document.sform1.password1.focus();     ! S9 [7 y" W; |4 K% d
  return false;
1 H- Q* F4 u" A" s) V0 p. l  } ! c& e' q+ t5 b) W* w! h* x
if (document.sform1.email.value == "")     
9 T. c+ L+ ?' R; B$ {7 e+ J  {     9 n  V* Z8 l8 O
  alert("请输入您的E-MAIL地址");     
1 ]) A$ R3 }/ M" D" _" Z- j. m  document.sform1.email.focus();     * G2 z: E- o8 _2 d8 @8 W$ e  Z
  return false;     
8 h+ p, A' F6 ?; ~/ d  }     
5 u$ Z3 w: I7 B% z% a2 w0 d; e      9 A$ ^; w. @: p9 }5 @
email=document.sform1.email.value;      
% k; m6 A# w+ z% u# g. P; u emailerr=0     
' q$ l8 Z: b8 N2 A& f/ m. R( k/ F for (i=0; i<email.length; i++)       {2 Q, R- g4 l, @7 `" x
  {     
$ ?  _& k3 s- B8 l. a$ s  if ((email.charAt(i) == "@") & (email.length > 5))     
2 o! [3 o( F8 ?/ w0 e  J( x9 m+ y/ l   {     
3 K5 w4 W% Y% ]/ o     emailerr=emailerr+1     " k  ~4 G0 g  @4 s
   }     + N; ]- O8 m. }9 d* l. c9 k
  }     ; r3 y: }- ?% l) Q. j
if (emailerr != 1)     8 W6 }% b3 X+ U6 ~
  {     
& _6 }: o; T9 z* a& x3 P) A( t. d2 n  alert("请输入正确的E-MAIL地址");     " Q/ Q. a, l- x+ j* y4 L, j
  document.sform1.email.focus();     * o/ m( d" K8 w3 U0 S% B* D1 ^
  return false;     5 X7 T' u/ C+ ?$ J
  }           
' t3 T' b& g3 {8 n1 F  / q  o+ M6 N% a+ {, h' A
if (document.sform1.checkask.value=="") - M9 T/ i1 U. {- n
  {
! V7 p. g2 h3 G. D   alert("密码提示问题不能为空");     
% `# s5 [" G; T   document.sform1.checkask.focus();     
. Q! E, b* j7 t; k4 v   return false;  $ j7 ~7 c6 s1 U- D8 A
  } / m8 n5 @6 M( o0 ]/ g
if (document.sform1.checkans.value=="") 2 e  l" K/ K2 j) M2 f+ v; }3 n; u( _
  {
7 n. M, Q* f; o' ~- ~* u( O0 v   alert("您的密码提示问题答案不能为空");
" @# l" d  ]8 @4 X9 `- n   document.sform1.checkans.focus();     6 i/ d( \: Y# v- I9 ~7 t0 [& j4 z
   return false;  
* Y! x: s0 m" j) z8 s9 p4 s+ }  }
3 h" A2 U+ H5 ]# R" z return true;     
" m9 V# S9 L0 C, L     
6 z! q2 }4 Q/ r% A} ) H  h' ~1 b6 j  u9 w
</script>

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