返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
# Z" ~" y% M7 u/ c<script language="javascript">     
+ N& g' {/ T8 `% M7 Efunction IsDigit(cCheck)     
2 j& ]4 q" H' V1 K/ i. _. O {     . O5 |% ?  s9 s; O- {6 t
return (('0'<=cCheck) && (cCheck<='9'));     / l4 Z( [0 T( D; v. u
}     ( c; g- S/ I4 p  a9 [) s3 n
     2 `; l/ A9 d# S
function IsAlpha(cCheck)     ) y& v. K. S% E8 f8 A- q* q
{     
) L" X' A) o' P) `: g2 Z2 P return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
) f/ q+ H% b# p }              0 K0 l. C) W7 T
      
$ J# ^# K: w) @+ `! N" q8 l" Lfunction IsaNull(cCheck)          - k9 Z4 c% s, L0 N2 ^0 N
{          9 j7 R" H3 r- E, [  Z
return(cCheck != " ")         7 K  B6 a1 s5 p$ @- R6 d) E
}                               + W+ V8 e4 h$ f2 f: O0 j# @# n+ ]
      & Q: b5 F; c* C( c
function checkform()     1 y; m# \' s0 Q, |+ h# j
{
6 p" y# O1 x9 A  id = document.sform1.id.value;     2 j: Y0 C) }# S1 a  [
if (id == "")     8 d3 _, d. B7 s* D" J; Z& r
  {     , X' V" H4 u' [% H+ y
  alert("请输入注册名");     
" }8 h" j% A. r) k' z0 c  document.sform1.id.focus();     1 V8 N# `' u4 D5 o6 s
  return false;     
. {8 }8 ?: \  D3 }  }     1 |- u5 h/ \  M5 \# m' O1 ~: k
     ( i7 i* K- g2 M: V5 w% I- R- V$ C4 d
for (nIndex=0; nIndex<id.length; nIndex++)     
9 e$ x2 K( G6 [! t1 s  {     
8 [4 c' e/ N3 l3 ~  cCheck = id.charAt(nIndex);     4 K3 h0 R; r+ d
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
' a/ f1 E  Q2 W8 J, @4 X   {     3 ^+ X2 d2 Y. W" r/ B8 C
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
1 G1 W4 d1 l3 |& m: ]) Q2 Q( q' C   document.sform1.id.focus();     
# Z' u1 V6 B2 X0 R3 p. b   return false;     
9 Y+ ]3 V  A0 A0 ]2 ~8 n( _0 X   }     0 `7 m, Q# ?- b' Q
  }   U7 @3 _' _% e5 t9 J- t# T
  chineseid = document.sform1.chineseid.value;     ! ?" ^) O* S% w0 j( d' G
if (chineseid == "")     ) I6 S1 R& f+ b* z
  {     
% `, e! e% R. w0 I7 U% R) k  alert("请输入中文昵称");     4 o/ N" [8 w1 y/ s
  document.sform1.chineseid.focus();     3 ?$ j: x5 ~* t4 O0 ]) n! W  Q) a
  return false;     
# f: t- f* \$ s* G% D  ?  }   
0 R% c# Z" g" p password = document.sform1.password.value;     
# Q( R& y8 k7 _8 a- x# N if (password == "")     
, C. `  P# J% [) K  {     
0 E  J7 \4 Q! r  alert("请输入登陆密码");     
* X' ?" N3 ?$ w0 q+ N  a$ y  document.sform1.password.focus();     ; g; O& O7 H  t1 t- Q
  return false;     
# n  `/ t& U+ @! s9 @$ L  `  } ' ~/ ]' b& R5 B
password1 = document.sform1.password1.value;     
6 g- Q! c: h* D8 ]3 Q- g, S+ m) g: _' z if (password>password1)     
* z; J5 f$ b# Z3 ]/ v/ ?' ]  {
* E& n3 }+ }6 g6 d     alert("重复密码与登陆密码不相同");     
3 x% h! I8 C. g+ h- N5 ^4 f/ T  document.sform1.password.focus(); 5 I$ v; M8 N! f; p
                                document.sform1.password1.focus();     
, [# A) R+ X' V% U2 F+ k; N: D  return false;
6 l' ^4 b8 P9 ]$ @# a! A9 I. f  }  
$ S1 o- v- @; p( t. Nif (password<password1)     : o6 _4 f7 W8 \
  {
: c: I( X: l, N3 |' h5 M0 F     alert("重复密码与登陆密码不相同");     + ]) B5 O/ D! n6 ^% G5 n9 G& l
  document.sform1.password.focus(); 4 [; t2 g& `% S7 H: Y# C( ~5 A
                                document.sform1.password1.focus();     
) G4 d, T/ x" R% t7 v  return false;% i3 r+ s' d: \% t" J
  } + G/ o6 C+ ~- M* ^
if (document.sform1.email.value == "")     
3 Y* u, G# s+ n: Q) I  {     : W% x# x; M; I9 L  C, H& h1 J1 E
  alert("请输入您的E-MAIL地址");     " C2 O1 i' L3 F& y0 }" l
  document.sform1.email.focus();     * m7 O1 R2 n) y
  return false;     
, d8 n& }% J2 L* G) A) [/ T  }     
& }  q' ~) t2 k, G% }" Q  N      1 K5 [4 y1 _% E7 e- k4 N. P
email=document.sform1.email.value;      " K! X; F( O: X5 i) n# x
emailerr=0     . i. O+ x+ @  l* D5 p
for (i=0; i<email.length; i++)     
1 F. {. X; y4 I/ E  {     
8 @! L: {, F+ `9 _$ f  if ((email.charAt(i) == "@") & (email.length > 5))     + `# T2 b4 i+ _
   {     
4 }* n2 h! O) i. B: t1 O     emailerr=emailerr+1     
# D& b) K7 G7 x   }     4 D9 L( E" z. \+ |- x& x; Q
  }     
" O1 x- l0 h1 M if (emailerr != 1)     . c4 j5 o( @  T7 I, t# u7 G
  {     
  c" g& T! d7 v! h  B# G  alert("请输入正确的E-MAIL地址");     % r( K+ k7 ]. ]$ G9 ^% s
  document.sform1.email.focus();     
1 w6 e2 t5 R* u0 j" a1 v, S5 W  return false;     $ Q1 h( x: e! h6 e( I
  }           6 L, E" p2 w$ c, ?' c
  
' B, G# ]+ X- P* X if (document.sform1.checkask.value=="") & w# }6 u. L9 l9 ]. d
  { ) q5 n8 J: c% I! t- x0 o
   alert("密码提示问题不能为空");     ) x- S. M8 j* J" w" X: a
   document.sform1.checkask.focus();     
* o/ U: t4 p* u2 B   return false;  , o% s2 i6 S6 {7 F3 G; v
  } + r6 V% l" _  u- C/ z4 [, L
if (document.sform1.checkans.value=="")   c. Q5 t0 {* }& j  p0 A6 Y' N
  {
% K, }& {6 `2 ~, z   alert("您的密码提示问题答案不能为空"); 4 m* m: b8 B( Y7 }
   document.sform1.checkans.focus();     
; A- a% T, Z: }0 G" |   return false;  % ~9 K9 p. [$ _6 r& e
  }( b/ Y- v. I# _( H# f# E1 _
return true;     4 ^6 Y/ F% G6 f; W, b
     
9 V3 K( p- f; A} % |$ e. Q* G! _; x+ \; C0 g
</script>

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