返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
, Y; A5 y4 V2 {" a6 t4 H<script language="javascript">     % G- H& m' U: d0 y& A
function IsDigit(cCheck)     
. d) P2 m! q8 Z- m {     " J, \5 J8 h* o  l5 J$ m) u
return (('0'<=cCheck) && (cCheck<='9'));     0 k5 h& C* l/ X& j# ~2 v, W
}     
" }+ t& A0 ]. M  h     ' u. x( o7 u, E; D0 E8 u
function IsAlpha(cCheck)     , a7 T( A; k; U; V$ ], }
{     7 T+ k8 R$ ]& N9 }+ h
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     8 b; y) W) y) r4 F; p0 z
}              $ Z% S. R8 s8 Y! R3 z* y3 Q& d1 t
      
0 K* g; N5 s/ l5 u! U; wfunction IsaNull(cCheck)          & N% ?6 O- ]: ~- y
{          % F( m! X) Q; V1 ~
return(cCheck != " ")         
  F5 a2 c1 h! F( g+ s }                              
4 {- s# r, I  N! J      7 c) m- K6 Y$ g. j0 {; q  T" c  ?2 W
function checkform()     : F; k+ M; V' v  K! W* |/ C: j! U
{
0 V6 S: p! r5 o/ \: h; J. n/ w  id = document.sform1.id.value;     8 ^6 z  |9 F* v( c9 P) J5 `
if (id == "")     0 |3 e1 z6 ~) s
  {     
$ k$ o6 U4 i0 e8 e5 r! s- p  alert("请输入注册名");     / m- n  L( C. A9 g
  document.sform1.id.focus();     1 C3 x4 d' }- e4 v9 x& I/ r& @# d
  return false;     0 X4 x; {3 c( |% [4 Q# A
  }     
. T. b3 F0 ]) W: n6 `     , L% B4 N4 y- o2 U  m* ?4 }* P
for (nIndex=0; nIndex<id.length; nIndex++)     5 [! o/ v& \1 G# [( v- n
  {     ! s/ m0 O% }; V1 ?
  cCheck = id.charAt(nIndex);     
5 V: q1 |# K0 H  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
3 `0 y4 q% Y5 h6 I3 E   {     + r" @7 h, I% {
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
9 y9 y+ w9 M+ V* q9 F, C1 s   document.sform1.id.focus();     . P5 U  y7 I; }1 ]1 ]# T. O
   return false;     & ^, ^8 L3 k: @- `; Q6 I7 P
   }     
, R0 k2 G: L, f" D, g) |4 u  } 7 h9 W4 V; S. f. H7 j7 r
  chineseid = document.sform1.chineseid.value;     
1 g  [. Y& a: y8 k/ `% L  {4 X if (chineseid == "")     
- W! C/ q* _$ }6 G3 }% F9 O0 }  {     . V4 W0 E1 F3 O
  alert("请输入中文昵称");     2 E# U" _4 n3 h8 {
  document.sform1.chineseid.focus();     + T/ S' f  x& m" A% j# M& y, w! h) Z
  return false;     7 q$ v: M6 p: C% ~9 V
  }    ) l  m! e7 \8 ]. j4 W
password = document.sform1.password.value;     & P" \5 Y/ V: _/ g8 M7 m9 W
if (password == "")     
) h+ Q! v& E  k+ _% D  {     $ u9 w3 S, S8 ?0 P$ b" ]+ m
  alert("请输入登陆密码");     % F1 v9 s) g& P: }5 r$ F1 e# H# v
  document.sform1.password.focus();     
% |( {6 N2 X/ q' V2 M5 _: ]  return false;     - a' e& O5 {# W3 y; A$ H
  }
; R4 T' N+ z1 o' n, F6 p) p) Z password1 = document.sform1.password1.value;     , u, k$ J: ]  U9 n
if (password>password1)     * g/ n5 u0 p5 Y( V3 e  u# T
  {
+ S7 Q% }  b- E" R* c+ }3 f9 D  |     alert("重复密码与登陆密码不相同");     0 V$ l  o; e  m
  document.sform1.password.focus();
# Q' v1 O3 q, N; }4 p' H                                document.sform1.password1.focus();     
% g4 v- N$ r# Q: Z  return false;
4 ~3 E) M9 ^8 P! S1 j  }  
" ~0 K! B! }/ u* Tif (password<password1)     
# k& k2 d0 g; f  P$ t  {
% p2 s  V: W* c     alert("重复密码与登陆密码不相同");     9 [) Y, M  f: U& G. C$ L9 K
  document.sform1.password.focus(); 4 K2 L3 c7 U, I7 U9 U9 S
                                document.sform1.password1.focus();     8 a& y* K. w! i- d+ U! F+ w
  return false;
( h8 W* R; x2 \( L: M  } 8 g2 i7 W& @  G( A
if (document.sform1.email.value == "")     8 t3 U# P' O- m: Q/ z( H; M- u. w
  {       m- I& z4 W) B) h9 t
  alert("请输入您的E-MAIL地址");     
9 A4 e- R% C5 d* w: ?6 `  document.sform1.email.focus();     
( `, U9 y% L) _) x9 |3 z  return false;     ' V( \3 f& n7 ]5 Y
  }     9 X/ K- Y- n& `9 |$ r  m! @
      3 a  |- Q$ M8 m& z5 y& C
email=document.sform1.email.value;      
7 @; m* b# Y$ I2 p- y emailerr=0     
% }' Q$ J: s1 T for (i=0; i<email.length; i++)     1 M$ {9 O6 D3 F# g* Z
  {     1 R6 X, E; U/ H0 b
  if ((email.charAt(i) == "@") & (email.length > 5))     % M# ^1 |# {4 r* }& v# a. [7 Y
   {     
4 L7 Z& G7 [& o1 v; v! F. ~     emailerr=emailerr+1     
0 M6 T$ o9 D4 o7 t  s- x   }     
# n, Y; [, |8 h5 ~4 q, }  X  ^* @  }     
/ N# A& r9 {2 t  n& T, k* f/ y if (emailerr != 1)     
1 l0 l5 A' N) u7 Y  {     
  x) V% S; C# V8 ]. j  alert("请输入正确的E-MAIL地址");     
# i8 t# V" A. ^  document.sform1.email.focus();     
( f2 r7 Y: J0 x9 `# f) s) c  return false;     - l" S& G3 N  s6 r1 |
  }           , D  C. ^) P5 K( k7 m+ k
    }7 Z  X, n; w2 G7 [
if (document.sform1.checkask.value=="") / z9 m) V( C3 u( W
  { : P& F; s" R! f" i- b/ T& P
   alert("密码提示问题不能为空");     6 c% F$ P, t: @% w) ~
   document.sform1.checkask.focus();     
( Z3 n: D: N$ C* }6 m( j1 k   return false;  " |: I( w; o! C& q$ R- Y: m
  }
3 C, N4 U1 q: d if (document.sform1.checkans.value=="")
" F: G7 n, |  I5 b5 w# ?  { * E" O1 r( L. V) t
   alert("您的密码提示问题答案不能为空"); , `7 g6 m9 d* E7 `% N
   document.sform1.checkans.focus();     " Q% Y& H$ x2 J6 ?4 A/ I& \* q  e
   return false;  
7 H$ [8 i7 f# H; Z  }
! k+ ]3 Q5 [6 w6 E' p: I4 H return true;     
9 o' t, u& `5 P     
3 v0 w2 z! M2 ~( L( x}
$ x' C* }  A9 X: C) ?</script>

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