返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:# O1 E+ s, L, i) ?' `( |% O
<script language="javascript">     1 ~3 Y7 n+ d* R4 J1 K7 j$ C
function IsDigit(cCheck)     ! |) r+ r1 }  k2 Q
{     
& ~; p! G& f* S8 }2 ^! j" d7 M0 {, l# L return (('0'<=cCheck) && (cCheck<='9'));     + q. ~& V8 `' W1 G! x
}     
! m" t8 t0 G1 p) U: y9 K' M, Z! m4 w$ B     
5 p8 ?4 _( O8 B4 U% F! nfunction IsAlpha(cCheck)     : B3 B; N, ]* z1 ?
{     % C) e( P& Q+ f  O
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     " T% B9 }) M1 a4 V( e
}              
& b& G; a4 M  H1 y' ?5 j; x, C0 J        o0 l$ E- H8 \0 L" h. F7 n/ t
function IsaNull(cCheck)          # z" i3 V8 }/ G9 b  r
{         
" K0 [- i) p+ i return(cCheck != " ")         ) n- R* h; e1 r- R* E9 _4 l. y: l& ^- `" }
}                              
( s- q; M1 T4 k. b$ ^1 s, N6 o+ D      $ _3 W& S# _% I: P+ Q) n% H
function checkform()     
- }- ]5 m6 N2 O/ H{ ; p$ }# J+ S  Q& x- w0 F
  id = document.sform1.id.value;     
7 C, |9 l, k- @3 ^/ D$ a2 V0 V if (id == "")     
5 F: T+ v9 u1 {5 W4 O  {     
6 l$ n) F( y- r6 X$ o; ]$ M  alert("请输入注册名");     3 A; y7 e% V+ r1 Q  c9 c& i" z
  document.sform1.id.focus();     
( X5 n5 A. d7 t  return false;     
9 k* L" b; t3 O  }     
: K# z; L% F) l1 e7 i; P- h' {$ w     2 f$ [4 ?" h( _  o  M& y8 r: M9 {
for (nIndex=0; nIndex<id.length; nIndex++)     " ]) f& S# V" k
  {     & J$ i  }" z% S8 \- L1 C8 C
  cCheck = id.charAt(nIndex);     ; w) C' c) f8 J4 n
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     1 a0 O; N2 {' C  x
   {     
& a# Z' j5 ?& o2 V' h" v   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     / `; `* l5 |, i: m5 w
   document.sform1.id.focus();     
% |' I2 `3 r. L( M   return false;     9 e& |% V2 L' e! l
   }     
6 }9 M% n/ A) ]  } & @0 C) O9 L3 ^7 J4 y% r
  chineseid = document.sform1.chineseid.value;     
. J! x6 m9 X4 v if (chineseid == "")     & x  R' [5 f$ Z: u
  {     " {- Q/ R6 B! M9 v. w- \3 S
  alert("请输入中文昵称");     ) q  e, I# v' W" N3 T1 l
  document.sform1.chineseid.focus();     
' i. \! m6 r* q9 J1 t9 P  return false;     
2 ]* |4 L9 o8 P  T; J) p/ v! x  }   
/ a8 W: h  P& H) w& L1 B0 G password = document.sform1.password.value;     8 @: s1 O  h+ c2 q) b. ?& F
if (password == "")     6 D8 s( x& J) Y5 p6 B9 a' _, J" X
  {     ; \! ^+ M* N& a7 E! [  {) ~0 [/ w
  alert("请输入登陆密码");     
0 N* j( Y, K# A, O/ b  document.sform1.password.focus();     ) b# G" L; f. R/ i$ `) F
  return false;     7 C' c+ N7 c  S
  }
' E* x8 Z- c, B  V* S password1 = document.sform1.password1.value;     " @& h9 d6 e& Z. V8 _7 F/ e
if (password>password1)     
# Z" F# n0 a8 m/ |, Q% m5 B  {5 {! s$ l8 Z& ]+ n/ g% B2 ^
     alert("重复密码与登陆密码不相同");     
( o' ?0 i" l/ N$ b  document.sform1.password.focus(); / R5 ^' B; w9 X1 g3 X# V! W
                                document.sform1.password1.focus();     
- c6 o, T- n' W, s! g% u4 Y/ \( l8 K  return false;% G3 d! r. e$ \; {; Y- S; }
  }  
: Z" e; S5 t& E& ]if (password<password1)     
! |7 v2 H9 q8 B2 k' [  {5 J( v" q( S- T1 k( Q1 F  T
     alert("重复密码与登陆密码不相同");     , d- z- l5 u  F
  document.sform1.password.focus();
' n3 q$ v, t+ O8 S( V5 j1 w                                document.sform1.password1.focus();     
3 Z% G- z' H1 H. b& v( P! ~& l9 {, U  return false;+ Q: |. J4 A7 v* V* R( f
  } & i6 j& y' [3 F; D. [  ?8 Q
if (document.sform1.email.value == "")     
5 g* D/ C) T* a* x  {     $ T9 x; l# v( I) S
  alert("请输入您的E-MAIL地址");     
5 G8 {% D5 `. i7 N, @% H  document.sform1.email.focus();     
  p7 D- h# D' ]) N" H4 n: d  return false;     
* h+ i7 L2 M' P, ]% x; d) ]  }     / \7 {8 H) t2 }  x! X
      $ k0 D, p& |& `# ?+ q
email=document.sform1.email.value;      
4 f( X; k* r. G3 M7 G: \. n3 A emailerr=0     ' A0 @. v" E( e) m/ ?0 H
for (i=0; i<email.length; i++)     % P0 e- `/ o1 I! X
  {     3 Q2 }) `4 R# z7 B5 n  N9 L
  if ((email.charAt(i) == "@") & (email.length > 5))     
" k, w& q6 l8 l' u. `   {     % z! P# ]# i" r  @2 U$ W
     emailerr=emailerr+1     6 m# y% o% e+ N& @7 }
   }     : l. s$ R3 ~7 ]% ^% @
  }     
# W& y/ ^- a8 A: x# f' P8 D if (emailerr != 1)     0 N. Y6 U: K* c6 c
  {     
% G5 ~' L2 i! Z  h7 w5 b  alert("请输入正确的E-MAIL地址");     
! }! o! }( f" }; @. b  document.sform1.email.focus();     
+ n* q' q% P$ Y! L1 \  return false;     
5 m1 M+ F' Q' C  }           3 C" b% h5 X9 ^! Q2 i+ ?
  
; `; i: W- S$ V' v8 F3 M if (document.sform1.checkask.value=="")
5 c' n! N% D" |5 x8 _' a# Q  { % a' w5 a( e5 n; H7 W/ P
   alert("密码提示问题不能为空");     
& S2 Q# ~. Q/ |/ o   document.sform1.checkask.focus();     * h8 q& e& g5 x' \
   return false;  / w: s8 ?8 L! V7 i5 T
  }
5 T  I0 @) N; f. @! k if (document.sform1.checkans.value=="")
# S4 I& m. Z) F; V: y7 ~  {
# u* h8 S$ H9 X# n& H8 c1 s   alert("您的密码提示问题答案不能为空"); 3 x0 r  u' O  T
   document.sform1.checkans.focus();     
# ~2 k- Q! d8 }; b% @' m: P   return false;  2 i3 a4 `9 Z( J  p8 J: l) _2 O
  }. v' K1 J' E2 c( f8 D; I& G' z  B
return true;     
  x: G/ i* f1 c, z8 W     
- ]1 Y1 ?8 x- a. x) ]' T}
9 n+ }0 [3 [" U. [7 g% F</script>

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