返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:# v' \4 d1 Z6 I  d
<script language="javascript">       j2 h) i2 p) r4 Z' ^; f, H
function IsDigit(cCheck)     
' L3 H- \- W5 x. y5 K" Y' S) B {     
4 o8 W9 D* f7 { return (('0'<=cCheck) && (cCheck<='9'));     8 R4 }/ H9 o+ Z/ ?/ b9 j) T$ s
}     
1 x. {% n6 _. o$ s) |7 C     
% \- \  J) j# M2 S: o3 Zfunction IsAlpha(cCheck)     * }  j! j- w$ w, l$ n1 Z. |% `+ p
{     3 ^. `4 W# t5 D1 p+ T* v- B6 B
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
" y: v: V  h, \4 e" v }              6 c7 l( h; @! x
      
# |, \, i8 j5 X! a) `, T$ wfunction IsaNull(cCheck)          % b0 i( P/ C1 ^. n9 J
{         
/ c$ x4 f6 i7 ^* p return(cCheck != " ")         6 R/ `: U4 k: n7 o, l1 n- [
}                              
; e) x, b2 j" ^, c6 z& d      
4 l; f- a0 m  m; \4 e" r9 @function checkform()     . ]2 D4 D% P' o  R4 S. w
{
" w# K. b5 N0 @  id = document.sform1.id.value;     
+ [5 O& K6 D+ P8 C if (id == "")     
( ]& V% z- C- H8 z4 b' K. y- w/ E  {     
; n' |1 m3 P) z. C  alert("请输入注册名");     
% ^% T+ j5 p4 s9 @$ e0 S  T  document.sform1.id.focus();     
4 ^: b: f- {$ F3 _( W- k1 ~4 J  return false;     
: p! d# `) [- I/ ]  }     
5 ?9 `  P* K+ @# i0 M$ j       M# T* N" e; J1 q8 L
for (nIndex=0; nIndex<id.length; nIndex++)     8 o; a3 f' L. ]& D% q1 F
  {     6 ^6 O6 k$ k! ?4 z* B/ c8 f# j
  cCheck = id.charAt(nIndex);     9 B$ y% v9 y4 L" ^
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
! M$ L1 {9 Q5 k. x; f   {     7 v5 y3 M% X6 N7 S1 H0 d5 U% ?5 f
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     + G+ o/ t% G. Y+ Z$ Q7 \
   document.sform1.id.focus();     7 {" q8 j+ U/ l& J- D  p
   return false;     
3 s/ B- P! C! G. L% D   }     3 j0 U1 W2 j( _7 |( R: E6 d& w7 @
  } 8 v8 Q9 n  {$ K) H0 ]* L
  chineseid = document.sform1.chineseid.value;     
* z# |( b4 p; K, h7 k+ N if (chineseid == "")     
6 N- \/ {8 K/ Z% a8 e  {     6 p. g8 D; i# s2 `
  alert("请输入中文昵称");     3 @  r2 W9 h- V+ q: m# o3 Q0 P
  document.sform1.chineseid.focus();     $ M$ {6 r) o3 U: I# E1 ]1 s6 v" c
  return false;     
- D4 g4 d: z3 t/ i  }    5 G: H  Y# d( k8 z0 p5 G1 G" ~
password = document.sform1.password.value;     # o* s# `" ^* [8 d! }5 D
if (password == "")     
' B* R* {% z% P2 W  {     3 m* X7 W0 l: {3 F
  alert("请输入登陆密码");     
$ [& N+ w& _7 ?& l' l  document.sform1.password.focus();     6 M* l. a" k+ m8 Y" ~
  return false;     : _# U" u5 t9 G& I) P
  }
2 V5 u# _3 ~8 D7 f/ W7 M! f password1 = document.sform1.password1.value;     " G( u! t4 s( @0 t. ]1 I4 _' O5 t% r
if (password>password1)     ( q5 E6 W; x, ~) y0 p; G: A2 {' T
  {: {2 q9 ?% X& ^8 i
     alert("重复密码与登陆密码不相同");     + `& l' Q) j  [+ d
  document.sform1.password.focus();   R* b5 @& m9 s5 b" k! x
                                document.sform1.password1.focus();     
3 `, A- X' N1 S0 N  return false;% \* {) `2 G5 C) y; U; j) w
  }  
6 f& C0 Z' P* x4 S3 }. dif (password<password1)     . H, r0 B3 \+ W7 Q9 d
  {
7 L3 W7 }1 l3 L: g: h  `( R     alert("重复密码与登陆密码不相同");     
$ N' A! c  F* Z; m. |/ \, V4 F5 e  document.sform1.password.focus(); + [2 Z( _3 Q8 h6 ^9 e2 ~
                                document.sform1.password1.focus();     9 s% B7 c  y& F- s
  return false;
& v$ {7 {4 |% y* M7 A  }
; M9 f6 n2 T8 l) N" z  E' S$ g if (document.sform1.email.value == "")     / ~% u! i$ ^* x/ V; V
  {     ) w2 ^( [4 j. s" b7 S
  alert("请输入您的E-MAIL地址");     
' F, X4 R3 @: Q$ r# P" ?8 q( B  document.sform1.email.focus();     0 f7 F6 ]$ B; w2 j, t8 w. |
  return false;     
0 E/ o, y6 D; A* t  }     ! a$ H' X0 T' t) E, F& w- H
      4 ~/ E% E* Z+ U7 V
email=document.sform1.email.value;      
& ^- ~1 o% g2 r& v emailerr=0     # Y: P) S5 n/ A
for (i=0; i<email.length; i++)     
% `% ~4 }: |" |" L0 S6 k  m  {     : T5 h- i7 s' ~8 e6 E) X5 E
  if ((email.charAt(i) == "@") & (email.length > 5))     
9 B7 f9 S; x) m: u7 B( M   {     
8 s/ O8 W& v* ~& t$ K7 Y. j- t     emailerr=emailerr+1     $ n. O" n. K) z+ R8 I
   }     
, s) k9 A  h6 E  }     
: o3 j! o' t, Y/ |* s. X7 \ if (emailerr != 1)     * p8 K: D: F3 w4 H3 l6 r8 _
  {       b4 m. o" t4 x; Z) [% c6 \
  alert("请输入正确的E-MAIL地址");     / b: j8 x! G2 X" O6 y9 C8 e, b) M
  document.sform1.email.focus();     
( H- D* Y! N  f  return false;     4 u, ]0 `3 R* f. H# [5 K6 \. J
  }           
* @* f6 @* A6 \) u1 q; J# b* ]  % d; Y" Y# G  a1 F+ \7 R+ A5 ^6 K; t
if (document.sform1.checkask.value=="") 0 q$ Y, w) d% J* j8 Y( S4 Y% |7 h; [
  {
+ }& ]# w4 C- ?: Y' c8 S   alert("密码提示问题不能为空");     7 S  F9 v" F% t0 v
   document.sform1.checkask.focus();     
/ o% n2 _- i% H" g; ?   return false;  # ^; t% I' J7 V3 n, |: h4 C, S  P2 z
  }
" C* \5 q. J/ n+ l if (document.sform1.checkans.value=="") " X5 u7 R, _1 t+ K9 T
  { ; N4 {2 f) F0 Z
   alert("您的密码提示问题答案不能为空");
& j/ d, d+ A  I  p& r8 M2 w   document.sform1.checkans.focus();     
4 h  ~& A3 y# s6 k9 r. J9 K' y   return false;  
. {: r7 x* o  Z, z( c( i  }
" _' `: z* d3 _. j6 p return true;       n* I5 u; j( R3 _) r4 V
     
) j% g0 O( R  ~, U9 Q; h& x* E6 h5 i} 0 s* y3 o+ H# \. A$ ?/ a  g& t9 e
</script>

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