返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:; b$ F# g& v- T# B9 o2 n; ~
<script language="javascript">     4 I$ o7 y/ \6 w+ {9 u9 x: r
function IsDigit(cCheck)     
$ }) ^5 A, P' B. C, Z; f7 r {     # j, B4 l& j: M# l; ]
return (('0'<=cCheck) && (cCheck<='9'));     
2 U, `/ T' E( M9 q6 b9 q# C0 t }     4 U1 J" m) Y' L* J, z4 B/ x
     
  l' r/ G& ?; R+ S, a- ffunction IsAlpha(cCheck)     3 a9 j0 J% m) K9 p
{     4 U7 _) c/ F% m
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
5 R: `3 u) u& T5 J) C* s3 x }              
9 K- G' x  S7 @! e5 R7 m5 Q4 C      * R9 A2 t( F) Y# y" D# a
function IsaNull(cCheck)         
6 D3 X) |5 F9 R0 X4 X {         
+ c( m7 N2 }; M+ t& }: o return(cCheck != " ")         5 c& g3 V/ R: a
}                              
: s7 _- Z+ n/ {% c/ z( L      4 V' x0 A6 G% O
function checkform()     
  C, q3 y  _$ {% C7 {# `{ 1 B/ o, V1 p2 v+ n9 i: A  {
  id = document.sform1.id.value;     " m! ]% Q9 c# N, a" y& E& }
if (id == "")     
' o; r  w! ~& Q+ K0 j  {     
6 H; h5 I7 I$ U1 L  alert("请输入注册名");     + f# I0 N0 ]7 Q5 U1 K2 i
  document.sform1.id.focus();     - ^. _" _/ C1 |) U
  return false;     ) H; F8 ^* e# D9 r
  }     % a9 P" Q1 m- m; ^. k6 B0 G; J
     
8 X8 \0 f9 X: _+ R: m: i" ?5 c for (nIndex=0; nIndex<id.length; nIndex++)     
( Z+ a8 S( F- B2 ~  {     3 {5 h9 I$ x0 M" G' X" n
  cCheck = id.charAt(nIndex);     
5 L6 s) H) K% ?& c. u# i  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     5 u4 e' C2 v% {2 ?
   {     
2 ?3 ^1 x8 X9 t5 ~- o2 X   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
# C3 H) G- J5 j$ v6 G   document.sform1.id.focus();     . k% E) F! N7 L) h' }, S
   return false;     ; @0 T5 d3 ~& a4 P3 M1 x! P
   }     - K  J9 I8 E, Y: t4 E
  } 7 F) I( \7 Z# V& ^+ `' H" _7 A
  chineseid = document.sform1.chineseid.value;     ; j4 s& ?: _! E, b' q
if (chineseid == "")     
; Q6 p2 |/ Q( W  {     
( x5 S4 }, U: A: ~2 O" G  alert("请输入中文昵称");     
, V0 h) C* E+ c( o. d" t9 ?  document.sform1.chineseid.focus();     
: r% A% f, ^4 X8 L2 Q; e2 A  return false;     4 j: i  N* J0 i/ m( A) }+ g; [
  }   
( |/ @% b( o# S$ C. P password = document.sform1.password.value;     # W: p" x! j6 Q  f
if (password == "")     , \1 A! d* I( l; e' c7 K3 u2 Q2 G
  {     # d3 N2 z  W9 O! O* T: ]" G5 T" J+ U
  alert("请输入登陆密码");     
( }9 h$ [4 p' O; ]+ R+ `5 ^7 Y3 O9 |  document.sform1.password.focus();     2 u+ X  ]5 k1 o6 ?8 s+ L& q0 a
  return false;     
/ f1 t9 t1 l% p* ^  }
5 O$ u% \8 [, d6 t5 g* F password1 = document.sform1.password1.value;     
" F$ b. a) ?  I" F& O if (password>password1)     ) O+ Z+ n, a1 a- Z+ p# L* u' i
  {9 E" ~/ ?' |& n- @* Z
     alert("重复密码与登陆密码不相同");     3 {5 W0 F) J$ i6 ]5 n* m. }, G( _; }
  document.sform1.password.focus();
* ]- L) z2 R. ?1 I3 x2 H! J7 I, _                                document.sform1.password1.focus();     / G" m5 W* }% r+ g  L
  return false;, r+ E, `/ i; F8 `& |, b
  }  
, j% _4 A. i  G! Y& Mif (password<password1)     
$ O  z7 M* L* j; u  a" ~6 m  {. @; z! E5 R6 ]5 b, x7 K
     alert("重复密码与登陆密码不相同");     
1 n# L5 L) Z/ n3 l9 x; }% O  document.sform1.password.focus(); 1 r" n; S6 D) }* j( R3 _5 Y2 R
                                document.sform1.password1.focus();     
0 O* ?) t. n1 P4 f$ V) d  return false;
, d" w: L7 q: n. j: i5 h# p0 B  }
# p* L+ N! b. O% L if (document.sform1.email.value == "")     
. r: k/ N' J' [* |+ o7 J  {     : }8 M2 a+ d) F: Q
  alert("请输入您的E-MAIL地址");     4 I# ~/ Q1 A+ G6 C& f
  document.sform1.email.focus();     / t  s3 ^6 b( v9 R& E, D
  return false;     5 ~7 l8 L4 }1 ~, W
  }     
- ~2 C. F/ b1 |/ M+ x& S6 d7 M! b      , ?1 I6 Q7 X' `% ]* g# m' ]& I
email=document.sform1.email.value;      
2 a* z1 |" ~8 N4 F: z, C emailerr=0     7 X, d- ~5 D. T
for (i=0; i<email.length; i++)     4 V+ O9 M# z& ^5 U3 v& u
  {     
* Y# I2 ^& r# \2 \9 W  if ((email.charAt(i) == "@") & (email.length > 5))     ) \1 I$ B" n7 H% ]
   {     
( X3 J1 p- e1 K: g     emailerr=emailerr+1     ! c) e' d$ }9 }
   }     
  l  ~' {9 c, A' Y6 d  }     * E0 F, `$ p1 a, v  Z
if (emailerr != 1)     
7 |9 G: q) r* p$ {5 \+ @+ C# a0 d- t( _  {     
2 l* `! f, e/ j; N; o" g  alert("请输入正确的E-MAIL地址");     7 z. e5 S* a& @1 W$ C: B% X8 F
  document.sform1.email.focus();     / O- X$ C7 V/ a" _
  return false;     
# t% p& {! r8 s7 N  }           " I7 s2 x6 U! s9 e' h
  ) `8 Z. E- ^8 E2 U( v
if (document.sform1.checkask.value=="") 1 s9 t2 d  R  c# L) L  {+ t
  {
% n( f1 o6 I; O; q8 i   alert("密码提示问题不能为空");     , ~5 G" m9 \, R5 b" U. p8 |2 R
   document.sform1.checkask.focus();     + @7 L1 B; l; H5 s1 G( e+ j) b
   return false;  
- L, e! H; n9 T; l& F  } 1 V, L4 E$ W0 a, ]6 j0 h/ n4 d
if (document.sform1.checkans.value=="")
# _2 }, N2 i, L# T: s, e; V0 Z8 V  {
$ o8 T( g" W" g   alert("您的密码提示问题答案不能为空"); / D3 C. H, S( e
   document.sform1.checkans.focus();     
. Q: f$ F* I3 m% A2 p% u: b' [   return false;  0 p1 U- m; d7 o) t3 b
  }' N9 j5 }% |( V( b: k1 L- H
return true;     
+ {) k, C$ k2 q2 F     * h* M7 O  l" F# E$ |5 \6 O
} ( g; {0 L9 y  p0 f" @) |5 r
</script>

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