返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:: W/ g& H2 Y6 g3 H
<script language="javascript">     
7 J! o+ x! E. T5 w  M) P; z. z1 wfunction IsDigit(cCheck)     ' U6 H6 P  }7 w9 u
{     
2 z& \0 E# |5 x% \" y# a3 F return (('0'<=cCheck) && (cCheck<='9'));     
6 G1 B' t+ Z7 U0 c }     
) [5 [4 ^7 x$ D6 ~3 ~5 G0 F     
0 J2 o1 s. u; I* ^0 kfunction IsAlpha(cCheck)     / d+ ]$ {! z) s/ y- ?. w
{     
; y  g, g6 Z! |5 B) } return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
- B& `) x& X! b) O: X/ i1 H/ z }              
2 N# C" v3 k4 F7 H: p7 U      $ b7 U& N6 m' ?+ S/ p. s; \8 A$ Q( ]
function IsaNull(cCheck)         
6 z" {4 K: q3 l+ D& P  K) M- K; u {          ( G9 |$ H: v* I" `; j2 p
return(cCheck != " ")         
7 W1 |( z# c9 d2 N% u  T }                               6 u6 G) x! l7 w
      
- l- s4 Y  y2 ^; y7 q- [4 d! Q  H3 h; Wfunction checkform()     
7 U. Q5 X5 \+ r6 N/ Z6 n8 g% k8 R{ 2 [0 b* g* c* u2 L' h
  id = document.sform1.id.value;     
5 u: s% l* J% b% a if (id == "")     $ [) d: Q3 v6 g/ t* V
  {     5 o& O. r9 h2 E) }( @
  alert("请输入注册名");     
: ]( ]1 L' x3 y  document.sform1.id.focus();     
. v! \. l2 r2 s/ I2 E  return false;     1 x" o* F1 y) d
  }     
: o% z+ M7 z7 M/ F& }     
0 s* o* j; ^- f& [ for (nIndex=0; nIndex<id.length; nIndex++)     
+ X4 j, y9 e- a) V# I  {     7 G/ q5 o5 C* ], I: _
  cCheck = id.charAt(nIndex);     ( a  e0 J& I( f0 x7 ]  L( K
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
0 g0 e1 [1 H& k# U$ H   {     / r5 ?  q" q" D
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
, A0 x4 d4 B3 T   document.sform1.id.focus();     
6 z+ T: _' a2 _3 n: K$ D   return false;     
, D8 c/ ~+ `0 v  g  E; m: Z   }     
/ b0 v. I0 K) O, L, w, ~  }
# c' }4 j, p9 j/ _  chineseid = document.sform1.chineseid.value;     / Z) i; p  ^5 Y( w; t8 |: j  P
if (chineseid == "")     5 I, g, w( K, J1 y4 b3 R. I5 m
  {     
* H4 A5 N- \' S, u# Q' {  alert("请输入中文昵称");     
: ?: f, {) Q9 F  \- e" C  document.sform1.chineseid.focus();     
3 ~$ }5 n  J5 n' r# q2 U  return false;     , Y% P( y! ]% W* q5 m/ m
  }    % E$ @) ]# k8 a- o4 q& v- a
password = document.sform1.password.value;     2 T2 i) R, V% v* N
if (password == "")     
. O" P* A- _. o9 p& f$ ^, a# x$ o  {     
, H/ R, B  K* ]& u5 a  alert("请输入登陆密码");     
+ i7 B6 L5 Y" W) F! U! ?% m9 J  document.sform1.password.focus();     
; U' Y3 L" ~/ ^2 V  return false;       w4 P3 L0 r4 n( D4 x( `
  } 1 g8 d) Z  k! ]& \: }0 |1 ^
password1 = document.sform1.password1.value;     ( J/ |: {: s- t) u' P- G( t7 d+ W
if (password>password1)     4 X) z, R, g: J* ^1 g0 x% s
  {
: H9 t7 V& }. p" c2 g- U8 n     alert("重复密码与登陆密码不相同");     
1 V( `* R" p1 u( F  document.sform1.password.focus();
5 G& k9 n% a0 u! n, X2 B$ k. A                                document.sform1.password1.focus();     $ G+ C+ s' ]+ }7 G) K
  return false;
+ ~- a0 ?- V0 f5 N/ X  }  
! E- n+ Q5 Z& S4 W: [) Jif (password<password1)     
" _: \/ @$ l' i- Z' s  {3 n! S* L& h" H; `
     alert("重复密码与登陆密码不相同");     3 d2 v, l$ R! l/ q* N$ @
  document.sform1.password.focus(); ! ^$ j; Z- W" x* C. }
                                document.sform1.password1.focus();     5 y1 t% i. s5 |( r; W
  return false;
1 ~# y9 a4 R6 @# I: R# c+ D  }
3 R3 Y5 a7 b8 v% i! u0 {. W6 U if (document.sform1.email.value == "")     ' A- S  y' W/ x
  {     3 G0 ]% Y  A! r2 c* ?6 h$ [
  alert("请输入您的E-MAIL地址");       _6 k- ^1 P$ S) F6 W
  document.sform1.email.focus();     ! ^. d, I% d$ x2 N2 C/ f1 n& Y. l
  return false;     
0 r* i  F+ ^+ }& e( A: o  }     2 {' Z) t8 f6 m
      
+ c$ i  Q6 b. ?; ?& f) f6 F email=document.sform1.email.value;      
2 S3 m+ t/ G( k emailerr=0     $ U1 d7 H8 s2 X; `: b
for (i=0; i<email.length; i++)     
( i  p. s, {" Q- W8 N  {     / c, G1 W1 F5 n; T
  if ((email.charAt(i) == "@") & (email.length > 5))     
8 H4 m2 b; G8 P/ r: r* M" W   {     7 l; t# ^! [& j
     emailerr=emailerr+1     3 x5 _! k+ B7 ^7 _8 Y% Y: @
   }     
- E1 ?# v7 s+ w& h9 |  }     ) ]( H( e2 E5 d' P+ x% B5 j
if (emailerr != 1)     3 Q$ t: h% i& p) @5 D7 \0 A
  {     
; i( C! F! {! p! C: `% a  alert("请输入正确的E-MAIL地址");     
. c) k9 v* m# S& R  y( ~  document.sform1.email.focus();     
, g9 y/ Q2 b5 m  return false;     9 _4 }" O+ U8 Y
  }           % g5 h5 w2 ]% v' b5 B2 {$ l
  
% T4 c$ a" g( u! Y( V2 n if (document.sform1.checkask.value=="")
5 u  B  K/ B( L+ t, ?  { " q, E' e, N8 p' O# J( _: A
   alert("密码提示问题不能为空");     
' y1 G3 Q' x5 Y$ V, \. z7 ?   document.sform1.checkask.focus();     
! n  x. R% m1 z- L! i$ j   return false;  
- B9 c( R8 |% i; ]; o! E! }  }
1 ^' F5 d" `- f, U7 o if (document.sform1.checkans.value=="") + I* e3 f3 ?! |, b* }$ n3 }
  {
1 U4 F3 W; M% b0 L* z4 t   alert("您的密码提示问题答案不能为空"); 3 B7 X2 n  [. ], U4 A! H) n
   document.sform1.checkans.focus();     
8 G" y2 u, u: T# H( P) A5 q, j   return false;  
' T; n6 B/ \+ r/ ^* h5 {  x6 F6 ~  }
/ R/ b7 |& c+ c" Q5 o return true;     
- J  T# f6 L4 _5 Y: i4 U     ) @% r' b$ `, j: T/ X6 ]- q
}
. G1 n# U' s8 j' `' ~% h</script>

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