返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
# d1 ?2 N9 I$ `/ t+ i: q6 ]<script language="javascript">     
, }3 q* \4 _1 ]8 ^1 `function IsDigit(cCheck)     " m+ \  m8 f: o7 _* A/ O1 W2 |
{     
7 n$ B; b3 c% T1 N return (('0'<=cCheck) && (cCheck<='9'));     
/ `8 x2 h( g9 {' F }     ( G, s1 U% s- ?5 v% H. @
     
0 r* q$ d1 T5 bfunction IsAlpha(cCheck)     
& u, f. @9 [, X, a {     . T- I4 k0 Y) e% A
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     - l+ l5 P1 B# F1 x- J! P
}              
  M8 S2 x  g5 g9 T      4 @& |* U5 O; j+ Y# ^2 X
function IsaNull(cCheck)         
, I* S9 t3 u5 U8 e! o- I5 ] {         
, T7 c$ ?) I# T  I$ v return(cCheck != " ")         
  [# H( A+ E: n: w* H3 R& V }                               9 m1 T. ]$ ]! k
      0 ~4 q, A5 A( e# _" t; D
function checkform()     ) n  F6 H/ t7 ^! \- x
{ * |# F  x9 _$ r! ]8 z
  id = document.sform1.id.value;     ; Q4 t1 [8 {1 Q8 a! C: |& ?
if (id == "")     1 k, t- _4 Y3 V
  {     
' \; I9 a; S8 C3 J0 I: p' x3 H6 ]  alert("请输入注册名");     ' G  x: ]& k* s& b
  document.sform1.id.focus();     7 B0 {2 w1 C% _; L/ u
  return false;     
1 R! B8 y! g) \2 y% J  }     
  ?% q6 c1 a2 _; x     
6 }4 D) V, Y! Y. @1 L# I. ? for (nIndex=0; nIndex<id.length; nIndex++)     
! V& n+ B; O* y7 B- u  {     
$ N- {" D( E1 a, T  cCheck = id.charAt(nIndex);     % a9 Q* V3 c" G- Y) ^2 E& N1 f5 {
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
6 `, x) p6 O$ F$ B) S   {     ) m  t% P- W" j
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
, z- `( i: \8 V4 H: d" l9 R   document.sform1.id.focus();     
8 t6 W% x( f% I6 r( l2 p* t5 M) e* n   return false;     
8 X" Q8 w$ N; H0 m! P4 [7 _' Y   }     , A$ {. _8 E6 L8 v3 w# K) y+ Y
  }
+ j5 d- ^6 Q: a# M* \$ C' Q+ ^  chineseid = document.sform1.chineseid.value;     
- a7 l' |& e& u# w* U" Q if (chineseid == "")     
: @/ |. W& M) r6 {  {     
  q, u- _, i8 c  alert("请输入中文昵称");     
7 s6 I' N+ m9 f& l  document.sform1.chineseid.focus();     
' g! b0 ~4 Z6 T! u  return false;     : W, i& X) t, l0 k1 @
  }   
$ H8 u+ x' g4 A  g/ u- j password = document.sform1.password.value;     ; G4 G, K0 [2 {0 s. d- V
if (password == "")     
* X. @" l8 F+ X0 ]( ~4 a! b  W0 v  {     ; Z- ?  e# I1 W, G
  alert("请输入登陆密码");     8 Z- H) Q+ {- x3 p, `
  document.sform1.password.focus();     " x& b. q: \! D- i1 L4 J. P9 Y
  return false;     
  h# j% D0 _3 k% X  } - Q, o  g- \6 V/ s
password1 = document.sform1.password1.value;     
+ H$ }/ A" ?4 R& ^. T if (password>password1)     : p6 m3 @7 R+ J3 V
  {
, I, A% w3 {2 ~! {5 K3 b     alert("重复密码与登陆密码不相同");     
6 K' t$ K" G$ {  document.sform1.password.focus(); 1 q% z2 X% ^) x' |8 q
                                document.sform1.password1.focus();     
, u* d+ s1 u% ]8 D, L  return false;- h; |1 T, v# X4 O
  }  9 p, C  p, e8 r$ ?  s- f1 i1 K
if (password<password1)     % B/ g5 I# B# S: a
  {
, x( E  B  V. _* s' F; ^9 X9 Y     alert("重复密码与登陆密码不相同");     
( x( X( `$ d. S+ ?+ }  @; w  document.sform1.password.focus();
; B; y" G/ f" D  R6 n" U: U                                document.sform1.password1.focus();     + Q' _  h* X' z/ ^5 r* d. Z4 w
  return false;# V0 j4 O! q2 J- X. x- U
  }
" z! L* |8 W2 m/ R- V( ^ if (document.sform1.email.value == "")     6 }; M  n( G" ]" |3 m
  {     
, i0 T" `" b% v  alert("请输入您的E-MAIL地址");     
5 B& n. ?* {1 t; [/ i  document.sform1.email.focus();     5 O5 j; w: V2 x
  return false;     
/ D8 M- y$ s( ?1 G. _/ U+ w" t; s9 x  }     
; f8 J6 v- @" T: _) g0 l      
, c# L6 D/ H4 G8 n email=document.sform1.email.value;      4 A* i- g% }9 m; @/ c
emailerr=0     
! K& h1 G! ?2 ?% j7 Y& z. [  ? for (i=0; i<email.length; i++)     9 L& q+ P5 u0 Y* `
  {     
4 ]  M' V. f  D8 D( y6 D, l  if ((email.charAt(i) == "@") & (email.length > 5))     , h. h6 x% H) ^, m( w9 E- j
   {     
5 T5 R0 b, v) A. Y4 Y$ |     emailerr=emailerr+1     
$ E- D  k. Y" ]; w8 q   }     
6 r0 Y+ [* h2 R% X* D  }     
- r' b3 ^0 E  m; u+ K0 N4 D if (emailerr != 1)     7 J* }8 n/ v) c- Q, f
  {     & @* [8 p$ e& M+ ^# w
  alert("请输入正确的E-MAIL地址");     
: \- ]! ]% C# q: O% ~5 _3 D2 |# V  document.sform1.email.focus();     
% C: C6 ^$ F; [7 o  ?2 k  return false;     
, z9 R) i- _- m- F  Y  }           
0 N: C( P8 Y" g  ( x( G5 l  e# @8 }/ Z
if (document.sform1.checkask.value=="") 1 r: M  i7 r- ?' K; N* X7 p# j
  {
1 S8 A1 Q/ O6 N0 [7 ~   alert("密码提示问题不能为空");     2 [9 \; {) C) Z& T( k8 _. D$ X, A# n
   document.sform1.checkask.focus();     ; ?2 k( t; o0 U* L7 q! X% s  \) s
   return false;  
; ^  c- n$ H/ b# {  }
; k  K) S) a8 N" m0 ?$ s if (document.sform1.checkans.value=="")
9 i- j3 l$ \# p1 u  { " L- J$ c. k# q1 M  f* s9 O' [
   alert("您的密码提示问题答案不能为空");
+ f& O9 w; o4 g7 G   document.sform1.checkans.focus();     / ]+ K% Q, g5 n& k. o7 Q+ }
   return false;  
6 z2 J* e" k2 U) r  i: R  S* f7 x  }
( e1 L9 @& v' e7 k# B+ V- ]5 K) I8 S) E return true;     
" Q. ?- m# ~' d6 a     7 J, c6 _% }. d0 I- s! q3 }
} 8 p0 W& n+ A3 G2 U, f% q, E2 W
</script>

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