返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:) d% P  d# w% H2 S. m* f/ d9 n& `
<script language="javascript">     
1 i9 b1 j4 F/ hfunction IsDigit(cCheck)     
& A: s% |$ g7 k. d/ `6 u  l+ A( ~5 b {     ( i) I8 |4 N' }1 g7 J6 l% l
return (('0'<=cCheck) && (cCheck<='9'));     
+ S2 I- \( w' P  o }     1 B& n2 v; j! R" o+ M& C6 \1 g2 J5 L
     ) D+ e6 t; C/ E: N3 h) J; Q
function IsAlpha(cCheck)     4 k2 z5 ~$ H9 F, m$ N( r
{     ( X. n7 `! Q- L  J$ k
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     7 ?6 ^0 B1 n; K; ]. S
}              
+ w1 ]- V3 E( ]' a; K+ A: n      
# O) Z; S& g6 n4 @# zfunction IsaNull(cCheck)          & {4 B* Y% P% V0 [; ]# Y) b. I
{         
; K1 M8 h; w) N6 g8 u, o: c return(cCheck != " ")         ! N& R0 k8 k1 H6 w0 D4 n9 ?' i
}                               & O9 j. i) x5 `. g
      
* @8 R0 y* M! a+ z$ Y4 q$ Rfunction checkform()     
4 W" {: o  j$ c; C$ q8 o{
1 x  e! B3 `5 h4 _# N, t  id = document.sform1.id.value;     2 {! ]. [8 _- ~$ D, |6 d
if (id == "")     ) S; Q% x8 x  z: ~
  {     
) z4 g; j8 y5 C. u- q  alert("请输入注册名");     ! J" R. Q. J0 N# L
  document.sform1.id.focus();     . Z8 W. U( q. P1 @
  return false;     
9 q; Y9 K; J4 `: F/ U1 F3 S" b  p. o  }     
9 r% ^. @7 {- B3 E  e5 d     & P/ Y( X8 m6 v' L3 {
for (nIndex=0; nIndex<id.length; nIndex++)     
* \; F: Y. k7 F  {     # B0 Q: |6 X  [3 J& Y
  cCheck = id.charAt(nIndex);     4 W& z6 J$ S) ]" `, S
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
! m6 C  @7 E- t8 t- }7 O6 W   {     
2 D; s6 `' G7 V& b" U# ]   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     + `* @+ A9 ]5 N. @9 |8 r
   document.sform1.id.focus();     9 g4 a& B, @/ K
   return false;     7 F. ]) |7 \$ l# V# F5 M* {* v
   }     
: Q. w% H1 ~7 X% S  } 4 w( ]  o( b, V* V+ X" V7 H+ m% C1 `5 [
  chineseid = document.sform1.chineseid.value;     
: m7 h8 z; a$ ^8 X  l) h$ q. \ if (chineseid == "")     
# J0 R; b7 H% w: M  {     ) \: B+ J! v/ c, @
  alert("请输入中文昵称");     
" [, a" W3 g9 h: n  document.sform1.chineseid.focus();     9 f; i! b! U6 f5 z3 e  S+ C. ~. d
  return false;     
: q7 Z5 J2 z3 Q3 e* ?  }   
1 u/ O9 x$ V8 M/ d password = document.sform1.password.value;     6 s4 K( V5 O2 r5 e$ G! N
if (password == "")     - T+ [6 @2 ]7 b" p" ]+ }
  {     5 N% `* ~6 |8 e  X' p
  alert("请输入登陆密码");     
9 f/ {1 I* l' i0 _; J  document.sform1.password.focus();     ) \4 y/ j1 Z, `3 U
  return false;     
. S7 D% I, w9 t+ n& T+ a, G  } ) |! Y  N6 k4 w/ D3 i' P
password1 = document.sform1.password1.value;     ! o" S# z- J; Z4 }+ j$ Z  T
if (password>password1)     8 w3 l1 |  H  P9 ^
  {) b# {9 N! R: N" N% P5 s8 U
     alert("重复密码与登陆密码不相同");     % ]/ e  m+ d6 y1 g% `" B
  document.sform1.password.focus();
  a' F+ j& e& l; r/ W                                document.sform1.password1.focus();     7 D+ u1 a; A& R5 w8 @$ J5 a* w
  return false;
" k( Y  I7 K8 k1 k( I+ E  }    w# M) a0 C" N! g7 M
if (password<password1)     9 I. ~9 i2 W1 W% E6 j
  {
( H' E! n( }% y6 r. P$ t     alert("重复密码与登陆密码不相同");     ) Y. d( a1 a. ?6 @- o2 H$ e
  document.sform1.password.focus(); 8 F$ x' T& ~/ U0 \5 u1 u, l; G/ a( Q: ~
                                document.sform1.password1.focus();     
* Y2 l. e8 y% S* y2 S1 S9 x  return false;- w/ @2 p8 Z$ V+ Q, _" B
  }
1 }9 P5 L1 z+ r% N3 L; F) R7 ] if (document.sform1.email.value == "")     ! G9 P7 g2 [: `) P" g
  {     , a2 E: w7 ]8 U* W3 }6 s3 X
  alert("请输入您的E-MAIL地址");     
: j+ m1 S: S8 ^- n. t. O5 m- b  document.sform1.email.focus();     ; L% C  z! c1 b' e
  return false;     
5 h. \( \' X! p  A2 g2 S0 Z! d- a0 c9 T  }     
6 x! C: h/ ~3 _/ u+ H/ }      5 ~6 F- [- e! w, s" H) _
email=document.sform1.email.value;      
" x' u4 G  B3 @- j, i* L( d emailerr=0     
8 N+ Y& n1 O. j) h. l: L' x for (i=0; i<email.length; i++)     4 p. }* K- [- I0 k1 T4 A& x5 C3 ]
  {     
" j% `! L/ j- w2 ?8 o  if ((email.charAt(i) == "@") & (email.length > 5))     
3 r4 v1 ^# q! i$ v% m' m   {     2 g! F0 u. P! J
     emailerr=emailerr+1     
* b2 [, |* h) z6 |! R  a   }     
& \- P; ]9 h& j3 o8 d( _  }     
; c. e- [& _  r, r& q1 Z) x if (emailerr != 1)     
% N' z4 c2 _& H# k3 V* s& b  {     : q' a3 V7 ^8 ^+ B8 s4 U8 P: c
  alert("请输入正确的E-MAIL地址");     8 }4 W* L9 P- L& r- Y8 E( G
  document.sform1.email.focus();     ' R" {# G& l, G- S; n. d
  return false;     ) A8 `" h* O. {4 K; ]
  }           ) p* `  V& ^% g+ b  g- J
  ( V: W$ V# |, _& A% k' o
if (document.sform1.checkask.value=="") 6 M( ~0 ?2 K( @7 o4 R
  { 7 g. m6 }6 n0 L* U5 [! L
   alert("密码提示问题不能为空");     ! ^+ {+ c# d8 I
   document.sform1.checkask.focus();     ( ]# U$ X0 y) q' D
   return false;  ' O9 g& a: s- ~/ s3 B4 c5 M" p
  }
, {  C0 n7 @$ g) a2 q0 p( ~ if (document.sform1.checkans.value=="") 6 Q% n$ [- W) {: V: t
  { 3 Y; p; F/ n/ t: {% }8 P( Y' P& G
   alert("您的密码提示问题答案不能为空");
( @; x6 U  g! ^0 o5 T   document.sform1.checkans.focus();     1 {. N+ b. l5 S! A" O* O. c$ O
   return false;  
2 S+ n* S8 b8 v  v4 n  }2 m: q! X# C5 M  l/ }
return true;     " z* T! T  r- r* K
     
: W7 d0 g9 C7 i' B. E- h# Q}
  g4 L' H. ~4 N6 h+ K6 |</script>

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