返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:9 i, D" \" E& d9 s% w7 ?# o
<script language="javascript">     : W# R6 x! Q( {  W  x
function IsDigit(cCheck)     
- B8 }0 ^- F. l7 z+ G4 M {     
) i- P1 `" ?, W" B return (('0'<=cCheck) && (cCheck<='9'));     
3 W0 t$ P0 c1 R, c& [ }     
: v+ I% X  N3 D8 G. O  ?     8 h2 F7 C, y+ d6 N1 n
function IsAlpha(cCheck)     
# s6 u7 U) z. Z; e+ g {     ; j! e# i2 {1 [1 x/ B
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
7 ?. u, o( H& l- Q) N" e) C4 x }              ( @2 j7 O0 Y  [+ h: L  q
      7 Q6 t( I9 c/ m4 X
function IsaNull(cCheck)         
4 M! _. e$ Q( c' _$ ]: Z1 ^* t {         
/ B1 ]* |7 ~3 @) t; y return(cCheck != " ")         
7 c9 E0 i- u& Z  ~ }                              
0 x: x& N0 `1 G  ]      
4 T8 [9 ]& b+ g% P* Wfunction checkform()     6 H9 p2 P" |% v9 S8 I9 y
{ ) C% J+ v. w8 n
  id = document.sform1.id.value;     ) ?# H9 Z  e# X# Q% e1 S$ I  }' h
if (id == "")     
& k' f' V8 d$ f+ s  [  {     
; v5 o6 \" W( y) |/ r: Q+ a  alert("请输入注册名");     
! v* g: g; v4 G1 X; W' U  document.sform1.id.focus();     
% e/ N& e2 H/ z  M  return false;     * ^8 K: m* `& m. P+ I) _
  }     
* ^3 g# L7 b9 t2 h     
) Q- n0 T5 N8 K for (nIndex=0; nIndex<id.length; nIndex++)     
8 |- F$ A2 O; e; Z  {     ; p+ i4 r7 A( e3 w" K( F7 t
  cCheck = id.charAt(nIndex);     
1 H& K0 t1 X/ {* n& h) U1 N  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     , d! L$ U5 \; r0 V: N" F
   {     + Z+ {( c0 m5 C+ }
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
0 v' y% S6 U; }& c/ y   document.sform1.id.focus();     
4 G4 N  P3 l* j% h& A  d2 W3 K& n   return false;     0 W6 i* A9 C8 j/ C5 h4 d# A: I
   }     
( z! R) R$ D+ d  }
5 Y* [( \7 I* O. m8 n  chineseid = document.sform1.chineseid.value;     4 k, w1 O8 a0 m
if (chineseid == "")     
8 W& W6 d4 q: U4 {! h2 X  {     $ C# @; H5 S5 B3 \
  alert("请输入中文昵称");     2 G# v5 M- g( E
  document.sform1.chineseid.focus();     
( {5 ]- s# B/ ?( D  return false;     7 S5 M) t2 S! e8 Q2 F4 O7 m
  }    0 k$ z1 G" T7 Y! s3 F& o
password = document.sform1.password.value;     . V$ z* Q6 Z3 ^9 r& U
if (password == "")     
; Q3 I! b: h* ^: Y2 V  {     ( m2 T5 ]8 {0 W/ o% ^9 H' e
  alert("请输入登陆密码");     
; \. I2 @5 z' A- }0 c; R  document.sform1.password.focus();     
. s' v% x6 U1 m$ _5 `  y$ G% w- K  return false;     : K& ?( ]+ [8 d/ r
  } , G0 l6 D( t, r, f) M4 }( G
password1 = document.sform1.password1.value;     * A1 `* z2 [" C
if (password>password1)     
: D* M) `8 p% |( m  {
" G2 P+ ~. ~9 `* A3 y     alert("重复密码与登陆密码不相同");     1 ~$ S# b5 H1 ~( Y; I. k
  document.sform1.password.focus(); / o* o  ?- f' c( k' c
                                document.sform1.password1.focus();     
; O2 `* e" T9 Y& y/ r+ f  return false;8 a- s. O6 z$ L9 f9 t) m
  }  / k5 ^7 W: X1 |: K8 g
if (password<password1)     2 v' R4 Z( j4 T- R! V6 E$ n, t
  {* J) q  V# d5 o+ U2 z9 q
     alert("重复密码与登陆密码不相同");     
) _7 M* u  V2 @; ^+ ?, _2 T$ w( V+ ^  document.sform1.password.focus(); 3 U1 x+ T4 ?9 t( Y0 C8 I. l/ R
                                document.sform1.password1.focus();     
  A/ I' ?+ G! _& x2 \: K  return false;6 c, t) g1 H- V6 a& @  s, F) d
  } . }, L" t! A  B. [- I" B' Q: c
if (document.sform1.email.value == "")     
5 H- N/ m+ m! T# K* J. v2 R  {     
( r5 \) Z0 c: E0 u# b+ L, F  alert("请输入您的E-MAIL地址");     ) q# k% F* B7 ?8 K  x1 E) i
  document.sform1.email.focus();     2 l. Z- T- }( ]: p$ N
  return false;     
7 V9 V1 R" H/ I+ g  }     8 ?% W. k3 x5 s# i# x8 {
      : \* n' k! ?; J, n+ J; p0 ~
email=document.sform1.email.value;      
9 f9 M. j" ^" d  ` emailerr=0     - X( @5 |. S4 L0 ?; _0 }5 s
for (i=0; i<email.length; i++)     6 L2 O( a( U4 w, `- u  v4 Z5 b3 F0 L
  {     
$ M  u+ g  d. \- f4 B  if ((email.charAt(i) == "@") & (email.length > 5))     
; h& {0 m( {% k1 t& }   {     " T# H! Z- o1 {
     emailerr=emailerr+1     
# m2 ?0 e% c! h( t( E   }     
) Y2 U2 j) e) G; e; u  }     
9 `/ [0 v- {. E+ C1 Y if (emailerr != 1)     
6 v. O! s: D; p8 I2 P, z  {     
2 d( d6 W& z9 R, K, T  alert("请输入正确的E-MAIL地址");     , A2 l. Y; X' s$ G" q
  document.sform1.email.focus();     
* W' j% I5 P+ E% x  r& R  return false;     ! h; n( h+ J1 T! v) f
  }           : p; i9 n8 `* p& P5 l% _, A; t
  
; Z6 f2 y  E! {; U if (document.sform1.checkask.value=="") 1 U6 s/ h1 G% m+ a- q; |. {
  { % W( d3 i/ Z; B' x% D' c
   alert("密码提示问题不能为空");     
) O  ~! u0 a" B   document.sform1.checkask.focus();     
  f* L6 P# W& D  h5 S+ p/ {  W& z% X   return false;  2 x0 N. Q& Q6 g: M8 S2 }" p3 V
  }
( ~9 e8 X* S. H, m, u! r8 [ if (document.sform1.checkans.value=="") ( w2 C% a, k+ g/ ~: x$ u/ w! t/ x9 G. ]
  { 3 y" H, D% K2 L8 f* S9 e
   alert("您的密码提示问题答案不能为空"); ( W# E2 K/ D$ o% \
   document.sform1.checkans.focus();     ' I4 p$ f& U: m2 X5 W* y
   return false;  + `* l' N( m$ a  w% o
  }
, ^/ F2 M6 q8 ]6 x9 n1 A( @ return true;     
+ Y5 N4 M/ K' N! J3 q, ?     
( w$ x$ c1 t9 E/ |3 ~} + X9 e" ?0 V+ W! O2 U
</script>

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