返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:6 {% @( }) ^8 o% u) S
<script language="javascript">     " v1 ~  ?6 n8 _% K7 g, M
function IsDigit(cCheck)     1 F- o9 |# d9 C( p5 {5 H( v
{     
; \9 A  V: Q6 d+ |- G return (('0'<=cCheck) && (cCheck<='9'));     
; E* \* V; ^( t }     
7 E" F3 ~3 ?" ]8 x     
& R: K- u2 N/ \: z: w$ _3 wfunction IsAlpha(cCheck)     
9 S/ t% Q2 \  Y! Y; q {     
6 C3 S6 l5 d8 P" v3 D) y5 k( Q return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     : i% N: Z# }8 d6 i$ o
}              
9 c5 d8 p/ ], `0 O; w' E1 I      7 I  w) ^7 w1 \1 U  o9 y( c
function IsaNull(cCheck)          4 d: Y1 t( t: t( A1 D5 v
{         
5 U- f  f% W1 i* p' R$ c( ] return(cCheck != " ")           @( w$ U6 e! p0 {) S/ d6 d
}                               ; @" v3 P5 v: j2 ~
      " k* k9 Z2 X: s
function checkform()     * e' g& c% Y2 o* T  w7 S+ m
{ . ~* N4 B* J( B0 [# u$ B4 g$ |
  id = document.sform1.id.value;     
4 |5 w7 j  j  N8 ^$ W' Z5 b if (id == "")     
; G$ ^% l& ]2 G1 y& \  {     
& \  {* a. F3 Y8 d" `& U) Z  alert("请输入注册名");     ; U7 `5 T! a, J
  document.sform1.id.focus();     8 \7 T- p; ?. E
  return false;     
: d6 Y( ~+ ^0 x  }     
6 |# W; ?  j0 M" {     
) m" u. A. }' s' P9 c for (nIndex=0; nIndex<id.length; nIndex++)     8 B3 F( S0 [. A. v9 b, Z8 |
  {     
; t( O2 h# M; j  cCheck = id.charAt(nIndex);     + p% B% E, y7 S9 M
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
' C1 p$ p4 t$ n3 a8 E   {     3 o: e/ @! \% P4 o" Q( v2 w
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
& I5 i8 `9 S5 `. x# Z   document.sform1.id.focus();     9 q: S$ C' ?! q0 Z* {
   return false;     2 q* \9 L5 v6 o7 O  `  W3 ~; O
   }     5 ?$ x: ~8 A4 F: G
  }
8 ^" r7 q3 x& v! _6 p* T  chineseid = document.sform1.chineseid.value;     * L/ k! {, z" N4 L. ~$ B! E
if (chineseid == "")     9 Z* _" [- F3 c  {# Z7 b. H3 M
  {     
9 S( Q" {( `7 w: A  alert("请输入中文昵称");     " O. Q5 h; L& T0 H2 |" v
  document.sform1.chineseid.focus();     
! l& S4 T+ |9 i5 z/ c/ `6 A  return false;     
7 A3 U! ~# q* j2 N0 c  }   
- y+ G7 X+ u; `( X3 y password = document.sform1.password.value;     
8 x7 s5 H( L) v/ G* m2 b! V if (password == "")     
( H/ l9 ]% a$ V6 {4 L  {     
* R+ C* ~( Y& @5 v( {5 t2 Q& h  alert("请输入登陆密码");     
) h$ U- N- B' J6 M3 c/ E! P  document.sform1.password.focus();     - g- D- F3 \0 m
  return false;     : e6 n' z/ I: h# Q& i3 u& Y
  }
2 W! f6 P, i, k8 f2 _! Q; @ password1 = document.sform1.password1.value;     + v8 {8 y: P) W# G$ b! a
if (password>password1)     ( s$ y: ]7 A* k( N2 `
  {# g9 V% A) p' W$ b
     alert("重复密码与登陆密码不相同");     
" i) k* M$ [6 _1 a" ?# G0 A  document.sform1.password.focus(); 9 t- h; m0 D2 T* T2 \
                                document.sform1.password1.focus();     , ~) n) _; R4 Y0 C
  return false;% k+ d, `% g" o  W
  }  
( _, x/ W- t" ?6 v$ Aif (password<password1)     7 ~  {( x8 B) B' R3 `
  {3 B9 e) V/ H/ m5 Z! X
     alert("重复密码与登陆密码不相同");     
8 [& U* K3 P* J6 m7 d; z  document.sform1.password.focus(); 9 d0 F" ]$ q8 _: c* e8 V" O
                                document.sform1.password1.focus();     & f! G1 M$ M' \, \( u
  return false;
( x( B* W+ T7 I% t  } 7 }1 K' t7 A! k( r. e* ]7 j. B1 n
if (document.sform1.email.value == "")     8 S- L( r7 |7 j& ^( Y
  {     $ e7 H- g- l1 V6 T
  alert("请输入您的E-MAIL地址");     ' w0 r$ M) C- C9 U1 x- q* C
  document.sform1.email.focus();       k- b& s% g8 [# p
  return false;     
! D/ y5 N1 }/ }1 _& z) s  }     5 |4 C5 }* P# \' i2 f* v
      : x- l, R: [) H, G
email=document.sform1.email.value;      
  @, ?, D/ q7 G6 q  |8 o0 |& m emailerr=0     
' f& G. ^- e/ g  Y for (i=0; i<email.length; i++)     
% ^% h: n5 r- d) i( N  {     
, ^& p6 i' p" J$ H& k3 c% ?  l  if ((email.charAt(i) == "@") & (email.length > 5))     
, x, l  U7 R9 k3 g+ f. y   {     ! H- I; ?# ~* ]  Z
     emailerr=emailerr+1     9 L: m9 u  ~% b
   }     
9 h  ~( _+ r6 I7 k5 p, G# x  }     0 [' f3 e# ]& l" h% {# X
if (emailerr != 1)     
1 V* `  D7 J. I) q; q, e! K8 d  {     . I7 f8 j, n$ K* Q( K' V! I8 i
  alert("请输入正确的E-MAIL地址");       a# S+ X, ?6 P1 B3 J  A
  document.sform1.email.focus();     
9 R. `) y8 F3 r- H' R  return false;     
+ `' k. w/ P  T& h- j2 m& z1 b2 P( O  }           " |7 i3 P% ^+ P5 A0 I
  
8 g; M' Q( }: Y; o; b2 m/ p! l if (document.sform1.checkask.value=="")
/ X$ J; A9 h: Z4 ]) o2 Q' x8 h  { + `/ p  q) s' J2 E
   alert("密码提示问题不能为空");     . i9 _/ W  c9 i, f  u
   document.sform1.checkask.focus();     # B4 _* o# Y% i# M& h
   return false;  
5 R0 p' i( ?, P$ X  } + [/ H' u& m7 Q; Q2 Q& B
if (document.sform1.checkans.value=="") ( t9 C8 g' X, |( m. [# c' @
  {
) C" f1 t" I0 j6 A8 ^7 u' x4 ^* @   alert("您的密码提示问题答案不能为空");
& [" U7 }+ ?% X% A, z7 Y9 ]$ X   document.sform1.checkans.focus();     
3 R, `. ?4 f! P   return false;  . q. y- A) n7 ]- x
  }9 O* V5 y4 n  c
return true;     
. v/ U: u: z  A4 {/ j, V       y: I! y9 p. N$ I
}
% z# {: R" g6 I+ J" C: l0 D</script>

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