返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
" i: t7 n2 _& j3 h: M/ I<script language="javascript">     & ?5 q5 q9 T/ x2 P* ^4 ]  R- d
function IsDigit(cCheck)     ! f+ k+ d+ {5 U! W2 F
{     " j, k! r  f$ z. R/ Q
return (('0'<=cCheck) && (cCheck<='9'));     * w+ e/ _! f; P* ^6 t. B+ u4 B  ~# A. {
}     8 B+ V: S4 J: o6 u
     
& T& `- V8 [4 Jfunction IsAlpha(cCheck)     
; m  }& V9 d6 j6 u; F2 |, Z {     
$ T' ~0 W8 S! r$ X return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     3 \2 ?! r' Q0 Q; O' ]. Z2 c; Y- o5 Y
}              
4 z6 x1 y: S5 p$ O8 A0 v; e      
& N: a0 G- z  i/ ?function IsaNull(cCheck)         
6 `  h) g0 f& p2 m( w3 o* T7 } {         
6 Q8 U: G3 G$ Z return(cCheck != " ")         
% K, M3 \$ E& N/ Z- Z7 S }                               + M3 R9 _; o8 `8 e
      - K9 W% {/ m" O+ \( [8 I; G# G
function checkform()     0 W( M. }% T) x4 W$ a# m
{
" |7 q+ R4 `1 [  l! `9 o9 |1 a4 k  id = document.sform1.id.value;     
) L5 m' ^1 u  W3 [6 h" {" K& | if (id == "")     + }2 O7 ]3 T& }: f/ l& l
  {     . r" {! y$ j! }9 U. I* v! e+ u( a1 M
  alert("请输入注册名");     6 y- V8 e/ r1 c+ d
  document.sform1.id.focus();     ; j5 V4 Z+ \: u! L( l" i4 a
  return false;     & V. S/ Q1 O3 `7 E- C5 E' n
  }     
, ?3 ^  l2 q3 Z+ i     
( Z3 P* r# i3 ~% |# c) t3 t' { for (nIndex=0; nIndex<id.length; nIndex++)     
. F: `1 T) X/ _$ q0 a' n  {     
' J6 d1 u, @( J1 \/ z* J1 I  cCheck = id.charAt(nIndex);     
( P% Y+ r6 L; E0 \  e  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     2 R$ O/ O$ s3 Q6 a3 A; l9 v
   {     / I0 M9 X7 A- H
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
6 g! X- S! n* p3 t) R   document.sform1.id.focus();     
: l! H' R6 c% ?7 e/ [1 \   return false;     2 @& e, n! I1 c/ i/ v) C% B$ ~
   }     
% k8 m% p5 H) H2 G/ R  } ( |3 S3 n) n6 H9 Y$ O% O3 H
  chineseid = document.sform1.chineseid.value;     
8 l  v  g+ r5 Y2 v$ n0 X4 j! X& W' ~" e1 x if (chineseid == "")     % z" I: m- d/ |+ h6 z
  {     
4 X& O" Z1 Y! q/ V9 W  alert("请输入中文昵称");     
! b' c5 V9 I, f+ o+ W" y  document.sform1.chineseid.focus();     
$ a$ G3 I+ |' |& G  return false;     ) q* `* ~7 \, f. _) V3 y
  }   
5 w- n: c/ a& i. R. C0 I3 \ password = document.sform1.password.value;     8 _. P' W, j! m% e! ^; ?5 j
if (password == "")     # j' P" \$ [* e3 M  j0 ]# A
  {     
; i: d0 y2 l) y( |$ Z  alert("请输入登陆密码");     2 ?0 J; O6 K6 Y9 l) |- _
  document.sform1.password.focus();     : N' @$ B3 m# o
  return false;     
( i6 _' N% Q  q# b  }
' Q% M5 ^7 J5 j9 _& n# p password1 = document.sform1.password1.value;     
4 S( n2 M, [* x' v if (password>password1)     
! s0 K2 G# e, o/ `  {$ R/ f7 W& c. ^* j1 M/ {
     alert("重复密码与登陆密码不相同");     $ c) e. E' Q3 K7 w
  document.sform1.password.focus(); ) `" g: G) p9 O+ Q& ~
                                document.sform1.password1.focus();     
! q; U( ~2 ^+ w% u) {" F1 o; m: n  return false;
# H+ Z- M) c& E! _/ N  }  
% F% q" \: A* ?; \if (password<password1)     + j( A) V  W$ {1 x5 j; ~
  {' _$ u# D7 Q2 H& {
     alert("重复密码与登陆密码不相同");     0 K+ J% h9 F( ^! q+ x4 c. k* t4 X
  document.sform1.password.focus(); % X9 S+ I) `/ I9 G
                                document.sform1.password1.focus();     
1 e" ]$ E* P& k! \6 t  return false;; L- |. q: }+ Q& N  t* Y, J. n
  }
; G0 f* E7 _8 `: z5 E" F7 g0 D2 J if (document.sform1.email.value == "")     
9 Y/ {  a& i) @9 q  {     
% z. s/ k" N( _3 c, \* j/ J  alert("请输入您的E-MAIL地址");     # P! S+ r* v2 _1 s
  document.sform1.email.focus();     + Y# Q. T7 X* x
  return false;     
  S, n3 J3 {/ a1 D/ r! V  }     
8 x# b: ]: D& C$ b& y8 z      . G4 R0 q& k0 f7 J5 X
email=document.sform1.email.value;      0 a" `8 ?0 r6 `3 |
emailerr=0     
# n6 @! g! \" h3 B( d for (i=0; i<email.length; i++)     
3 ~- ?0 g1 d. s  {     
! @. T- y; n- U0 C2 M  if ((email.charAt(i) == "@") & (email.length > 5))     
; h, l; A1 a5 n6 C   {       S' e/ o" X2 j: a$ i; U, j8 M
     emailerr=emailerr+1     - _* u( v! U2 {8 Z. ]! K
   }     
, o# e, R6 W8 N  }     
) d3 F0 t' l& E if (emailerr != 1)     
$ `4 ]; I+ S0 N/ U+ \" r0 N# l  {     0 X" ^- q. l; h) O" B- V% x
  alert("请输入正确的E-MAIL地址");     9 U8 t/ v% J. Q* {8 |
  document.sform1.email.focus();     
2 A$ Q- Y3 Q9 z2 ?  return false;     ! c) a; B# ^  Z
  }           8 r5 D3 k7 A2 i3 J" q7 ]- g
  7 G- [2 _& x2 h  z
if (document.sform1.checkask.value=="")   g2 E4 Z- d) P! t2 k/ L
  {
2 e4 l. N/ o' h( e8 K2 B6 t5 m   alert("密码提示问题不能为空");     
0 p$ v0 s; [2 I9 R# C* U   document.sform1.checkask.focus();     
+ B9 s  X- }4 N% f! q% Z5 x   return false;  4 Q  \( j) ~7 O! a2 L2 s+ @3 c2 D9 [3 H
  } 8 ^. c8 {& {, m7 I% f+ x
if (document.sform1.checkans.value=="")
$ {5 u- J7 j6 P& @" x: c1 w) z  {
4 R. M4 C$ w9 m- t- j, T   alert("您的密码提示问题答案不能为空");
; t6 W- }6 b  F4 W. |0 A! W   document.sform1.checkans.focus();     
, _  T; p& C+ B8 c   return false;  3 u& w; X% }  u' S( A
  }
5 {; ]1 a) g4 z. P# \ return true;     
: `5 k: O- I: X0 L% j- c8 G     2 ~  e' e* m  i
} % v2 O/ O$ Q8 A2 [
</script>

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