返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:& k. R3 e1 k' ]
<script language="javascript">     
: ^8 m/ b/ |# R3 kfunction IsDigit(cCheck)     9 C) O8 z1 ^  W7 f) y* w% L( R
{     0 a& w0 ^) w% t8 J4 i& R2 l
return (('0'<=cCheck) && (cCheck<='9'));     
4 T/ E6 h' M# t1 O }     1 F0 e* L% ^  K3 S2 Q/ E
     7 y6 U. ?. f. q/ t% s
function IsAlpha(cCheck)     
7 v' k5 k1 g) J& V {     
, c  U7 w; B: L0 X4 P- R+ a return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
/ Z5 r1 {. ?+ ` }              
  j; k) t( H1 }" @$ a      3 ?) @, B: Z( ?& g
function IsaNull(cCheck)         
! d$ Y" f1 N. }: }9 k- W+ Y1 ` {         
& W/ g: _- F4 R3 M0 g: u* h return(cCheck != " ")         " x% b7 d$ l5 O1 k* X/ x( _
}                               ( d$ k/ n3 g2 l0 ^
      ) X+ I" N: o: q' P' l5 r* w
function checkform()     1 ~; g  z+ S, j4 R+ q2 b
{ 2 k+ V# P' x7 T8 _8 D! k! G1 _2 a8 N
  id = document.sform1.id.value;     
% t/ p% N7 G8 B if (id == "")     ( b: q3 m* @5 Q7 n. [0 p
  {     
1 M1 U5 f6 ~& T  D+ G  alert("请输入注册名");     ) i3 r- A  d! o: {* o- w/ V
  document.sform1.id.focus();     - f  H3 K, k' m$ Z8 B
  return false;     
* s( M2 h( y* x  }     
' n1 r! y" t* ]+ b( e7 q* ]     % T4 P! `, }$ ?& K" F
for (nIndex=0; nIndex<id.length; nIndex++)     
" {3 {9 g6 y4 F5 E" X; o  {     
5 O- F0 ^6 Q8 b: l2 Z2 S  cCheck = id.charAt(nIndex);     , [/ o) W- X$ `. T1 y, ^
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     . T" Z2 ~6 l0 f$ U) t( p
   {     
% v2 r' `9 F& L! K' ?! b- j6 s$ @   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     7 \" J  I1 Q( x% L+ d1 n2 e
   document.sform1.id.focus();     ; e3 i! V4 g8 T* X
   return false;     ) B  U& M5 P# c) ^  ~$ n
   }     
5 c. o3 e8 D# u1 d+ C" O  } ; Z- }. B! a' F/ n. q: p" G/ \  J
  chineseid = document.sform1.chineseid.value;     
% \+ E* u% J, k  y# S; F if (chineseid == "")     6 [6 e' z  x9 f3 _# Z) }  n1 `: v
  {     
, _: ~  c8 r: e1 _# W6 F2 i  alert("请输入中文昵称");     ! Q/ X9 `* d* @
  document.sform1.chineseid.focus();     
( K; r: N7 h3 E  return false;     ( \9 M0 d* ~( l3 C
  }    ; A" E0 H0 {) U4 R- v. H$ G+ Z
password = document.sform1.password.value;     
; @+ m$ |+ t; e; z* w if (password == "")     : T$ ]' e9 n: {6 r. \9 i7 F
  {     + w6 [" m/ |. Z! w' c
  alert("请输入登陆密码");     
1 l" N: @0 _; {1 ~; E  document.sform1.password.focus();     
" D# d0 B/ u. r; F% ~2 ~" x  return false;       C* A7 Y$ H9 w/ R( e+ C+ [  _
  } ( J% E9 O  H3 s
password1 = document.sform1.password1.value;     : B5 I- ?7 E& E- V  y8 }0 y
if (password>password1)     . [7 v0 \! N% k2 k2 s8 `
  {/ i% {" Q7 Z, R
     alert("重复密码与登陆密码不相同");     & Y8 F: L8 ~- ^( R; v
  document.sform1.password.focus(); + H- |; {9 f# |6 f: K! S- P
                                document.sform1.password1.focus();     ( R# X# ^( E* S( t1 p0 r2 m
  return false;0 V# ?4 B( u' N, s
  }  
, x; `2 C* W& B2 o3 X' Y3 A; b* Aif (password<password1)     
0 N2 ?+ s9 _  i' ?& b  {6 ~& J* G& o2 r
     alert("重复密码与登陆密码不相同");     
9 _, r) h5 {9 q; X+ l  document.sform1.password.focus(); : D" v8 X6 o$ ^% z
                                document.sform1.password1.focus();       ]. ?  d) o/ s  z+ x# l; |! ]
  return false;
/ T; p7 _6 b1 l. Z* C* b; s2 R  }
% Q+ A/ g& j4 x$ H if (document.sform1.email.value == "")     
' l( @+ A" T5 i  {     * h' V) N3 R8 n* V
  alert("请输入您的E-MAIL地址");     ) `6 N+ g: Y# G' y" n0 w3 }% |
  document.sform1.email.focus();     ; M6 L  I$ @' h' S# e+ v& V
  return false;     
2 i+ D% R/ t9 x9 N  }     1 W! f0 A3 D0 U7 g5 k& k; c
      
! j; t! s/ ^( h! I) m+ r email=document.sform1.email.value;      + g$ o/ h2 O- G4 a, N1 b; M
emailerr=0     
$ |# c. F! H0 P% E4 | for (i=0; i<email.length; i++)     ' F: p3 c& W5 S! {* W) t6 x1 Y
  {     ) s0 f; v. E' F4 M1 {
  if ((email.charAt(i) == "@") & (email.length > 5))     7 ^8 y) B" X7 |9 A, J3 ]
   {     : {- Q$ [* o2 l4 s' t2 b
     emailerr=emailerr+1     
9 y' m8 N5 b4 K   }     6 l9 G4 p+ W2 r
  }     
# I+ i' g" j% l1 W2 k3 O, ` if (emailerr != 1)     7 @3 V' L4 B$ n; Q" S1 g3 k, {
  {     
' s: R, k  a, }8 z9 f  alert("请输入正确的E-MAIL地址");     # o& C- }- F- `8 H& m
  document.sform1.email.focus();     
" X+ {1 P% |- U0 Q% f  return false;     * g1 z+ k" W% b* y9 z2 B
  }             r$ {- G. K8 o1 P  P$ s4 J
  
/ D6 T1 p# J: L) w# E if (document.sform1.checkask.value=="")
3 X0 g4 S/ y( M- j6 C% @  { ) B1 P. q4 p5 I% E% W2 \6 }: H
   alert("密码提示问题不能为空");     
; u% E* \5 U0 ]' x  [# N   document.sform1.checkask.focus();     7 L( r( _% m7 V- [; s
   return false;  8 b; ]# ?) Q& K7 l: l7 O0 N
  } * Y. o  v. {' }, i+ ?; ]
if (document.sform1.checkans.value=="") 3 |$ }  H2 U9 t5 ]6 r. x
  {
8 s1 b- S7 D' Q' L   alert("您的密码提示问题答案不能为空");
: `- {8 u: z) p# }# M' X   document.sform1.checkans.focus();     
7 A1 W9 r3 _2 d* V8 m   return false;  
2 L0 _& P: B& J, j  }5 _' k) C4 ?& g" F; J! [% W- z! ]
return true;     " y8 x7 K6 s6 g: r6 U
     
5 [6 |; q" ?6 h" v/ R& q2 l8 s) M} " J4 `, u0 _6 i* q
</script>

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