获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:- n& t) c1 P6 @# Z. X$ W9 {. _
<script language="javascript">     + t+ f) i; s% ^. j1 k
function IsDigit(cCheck)     - ]/ Y# y$ t3 A
{     2 t2 S* u, G' j
return (('0'<=cCheck) && (cCheck<='9'));     
( Z+ ~* P2 \. F! F! I+ O }     1 y3 J/ m( K+ A; h6 Q. x( z) R
     ; _& u+ o( U5 {) _
function IsAlpha(cCheck)     ( {6 z, J/ t) O) e, i% Z
{     ( a; N8 Z+ m, D' n/ _& J; F
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
$ g# O- C5 B5 L5 ] }              8 M& [" R0 k9 r: y2 ^# ~
      6 M0 A) A3 V! }4 e, ^7 ^
function IsaNull(cCheck)          2 E' V8 K! ]( h/ o& a6 |
{         
9 l+ H: {* r0 T+ O% X( ] return(cCheck != " ")         4 T( E' y. ~0 t% u
}                              
* \5 e# R0 f6 ~, d! |3 \      
8 _4 j! r. W; B' N- Sfunction checkform()     
# X7 G' P) p, @% _{
6 v  s8 H1 }4 u( L1 y* q7 ]) U8 h  id = document.sform1.id.value;       D: e: Y7 z' q8 L
if (id == "")     
* D9 k  `% c& I% }8 T. Q  {     $ g3 M+ m2 H- M' g$ o
  alert("请输入注册名");     
6 Z* _( E+ C0 H7 X  document.sform1.id.focus();     
. P7 J& h4 B" ~* ]5 i  return false;     / q- ^2 T3 Z0 K: P7 H
  }     # z) o1 `# R1 D; Q) u* H
     
/ s; J, p4 e  g8 K) r' n for (nIndex=0; nIndex<id.length; nIndex++)     
5 x& J( H) l" B' \; e  {     6 R2 E, U- G% F* ]9 h% y- j2 d
  cCheck = id.charAt(nIndex);     
1 Y2 U/ ]+ E& u7 W  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     3 E3 L3 D4 h! M3 ~0 }# ]
   {     
! ~( S" C4 ]5 u1 [% V   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     8 e; F: w* T( M$ c& ]
   document.sform1.id.focus();     0 m8 v/ G0 C( Y% H
   return false;     
6 n4 N3 b, R/ c) ~   }     
2 |2 R; a+ C8 t  }
+ ~& L( C' p# ~& y! @  chineseid = document.sform1.chineseid.value;     3 W0 `) y8 }  ~4 a7 \3 i& V  b
if (chineseid == "")     ' Y8 Q9 V  s3 _
  {     
' Y: d5 k# e, p& O/ a  alert("请输入中文昵称");     , x7 S$ G+ B4 u+ w& \' @0 _
  document.sform1.chineseid.focus();     8 C& Z8 J3 }6 R* z3 u
  return false;     ' l) F9 u2 y9 m1 k8 @  n6 D
  }   
' @: L" _$ g, @; L! t password = document.sform1.password.value;     
* h2 u: y9 u4 e1 ~: U5 n) i if (password == "")     
' M! w* \/ V( L* z, m, l/ `) Z  {     
! O0 y2 @5 I# ~5 ^: x" U" _& g  alert("请输入登陆密码");     ! g2 p/ f4 w* s! v$ E1 M4 u% J
  document.sform1.password.focus();     
8 Q. r" K# }  x3 S" r" r$ ?5 H  return false;     
9 f( P+ v" n4 q7 r; f4 R( X  } - I& M/ K  B  r" u
password1 = document.sform1.password1.value;     . Q, J9 `: k4 L2 e2 f7 o0 ^9 ~
if (password>password1)     . F; D0 V) k9 x/ g0 L
  {
5 B7 n4 v: T0 Z8 H& F9 S! y     alert("重复密码与登陆密码不相同");     3 Y  h/ C& P+ T
  document.sform1.password.focus(); - s% y% H' i- ]. V  N0 C5 F
                                document.sform1.password1.focus();     
  n) Y+ W- r/ |, r  return false;
% ^: e+ T9 q6 S7 C  }  
* m) }! c, W( G; \; v. Gif (password<password1)     
; H1 w* C, G7 c1 G$ _$ d  {9 k6 N& \2 T( X, K7 V8 ^- t
     alert("重复密码与登陆密码不相同");     / W- W; L+ t7 K- a5 n. r
  document.sform1.password.focus();
/ B/ a* E& n  m% \0 I8 C                                document.sform1.password1.focus();     / A3 E/ E+ r9 t2 K$ m: e- w
  return false;+ l3 }& t: z, a( m
  }
* @4 Z0 P1 M( D2 y" C, E# `# G0 Y' A if (document.sform1.email.value == "")     2 \# m9 G1 a; {- f- b% y
  {     
2 a- S; w6 w# d  alert("请输入您的E-MAIL地址");     7 M, u+ s; J4 I: B. Z7 ~6 T
  document.sform1.email.focus();     
  K5 c! N( o& B8 e5 u4 T7 ^  return false;     
9 _' q& Z+ x) G  }     ) k' i' i. C4 u4 L* t' T
      ! @0 b1 O0 k$ n2 M6 X; `
email=document.sform1.email.value;      
- n5 B3 f! P% A7 \9 z' j1 `" a emailerr=0     # Z7 t& x3 `5 Q. G$ d
for (i=0; i<email.length; i++)     
5 K7 S# B4 T, n1 O( G1 L/ m  {     
5 V- P1 y3 I: w  if ((email.charAt(i) == "@") & (email.length > 5))     3 S7 M$ c' S% F% V( l
   {     1 X2 k  M& I, `; Y& ^, e& |' y
     emailerr=emailerr+1     8 t% G+ n* y6 H
   }     0 c; K+ @8 J0 k/ H! n  x* w5 r2 _
  }     7 Y% u( o. f* q0 T- ]
if (emailerr != 1)     
$ d* h/ u' t/ G- J+ y! ^  {     0 a2 a; I9 ~. G' t7 T' b
  alert("请输入正确的E-MAIL地址");     
" f& k5 V8 U$ o  document.sform1.email.focus();     2 K2 [3 I" e( F/ a0 s* Z, v; \
  return false;     : g+ b; b2 b# R9 b3 c" J
  }           / U) R# d+ |2 {8 ^8 p
  2 g# w- m% l& a  U0 w# e/ g$ l
if (document.sform1.checkask.value=="") 5 t' f5 H6 U, k( @  ?& u; k$ k6 ]+ L
  { ; R: M- W% C  |3 m7 D! Q2 }
   alert("密码提示问题不能为空");     $ e, f- l; i5 X' F1 ], j
   document.sform1.checkask.focus();     " h9 |2 p# S/ C9 {- z
   return false;  
" _% x0 |: b( i* \8 s5 p  ~  }
2 Y: p# K! Z5 w, L! s if (document.sform1.checkans.value=="")
3 [3 _, F) Y7 {7 s; ?) \+ k9 k: {$ O  {
0 @" A6 }7 I' I* j# _   alert("您的密码提示问题答案不能为空");
( W/ E6 I( O4 K4 M, b' M   document.sform1.checkans.focus();     
  R1 d! ^5 u2 _) {4 _   return false;  3 W' e! G! ~7 v: H- Z, N
  }
  [" i7 x# q, ] return true;     
: X# j; N% R1 V6 y! b     
) i7 d. H7 \" [. M}
9 I1 d; `3 C  X6 y- m7 d, V</script>

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