返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
& C7 P1 S2 G5 @& l<script language="javascript">     
6 u, x9 n+ ^/ v8 C: r' Zfunction IsDigit(cCheck)     
, l+ u- m: O! U& q8 k, J. J% Z {     
+ d3 N5 e2 P7 @; ?" J) H) s2 u* T6 b return (('0'<=cCheck) && (cCheck<='9'));     0 v  S& C6 A" B
}     8 {# `' x  {' T  o* j
     % c# F. O7 ?3 g% F5 o
function IsAlpha(cCheck)     0 Z. p/ r3 L1 ^! h$ B2 C) @. M, w
{     
. V: @( K/ W. I5 K& H9 j$ h+ E' s: y return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
2 v! c/ t3 [- m5 g0 { }              
8 H  p; Z0 E- F# S- P. @+ S$ }, s      
' o4 `; D, s3 B. `1 _  Nfunction IsaNull(cCheck)          - s! B! [6 n0 y
{         
6 G$ l% V) ~! H: w return(cCheck != " ")         2 f6 G9 e( {. q- u
}                               ' T# S: P5 v8 _3 |1 n
      
5 d( z! }; e3 L1 Jfunction checkform()     ( F& m( k: C) M  d$ g+ d* P4 M
{ ; j) z5 O. `" l$ w$ j4 F
  id = document.sform1.id.value;     
4 u! ?2 g, o3 [4 K if (id == "")     
: H3 ?9 Q' u1 k  {     " E% _7 ?8 x+ L% s- V
  alert("请输入注册名");     9 \! y- l- w6 y+ W4 c8 |
  document.sform1.id.focus();     5 K  h9 G( ?/ q0 A' w/ p
  return false;     
$ T" ~+ T+ \0 |6 ?  }     
& w- e: D2 Y! y" w2 I3 v+ \( T1 h     
4 F# n5 s: f8 F3 ]- u- p2 U  c for (nIndex=0; nIndex<id.length; nIndex++)     
8 c6 p. B  Z* D' A& w5 t  {     
3 S  U, t+ ]  S  w0 Y  cCheck = id.charAt(nIndex);     ; K% A6 r0 \4 H$ M7 {
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     % }7 q0 S1 l/ r3 w/ X2 m1 n$ v
   {     ( K7 E- s) S8 r0 W+ \9 M6 K
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
7 O- D  q. c* |+ r3 f$ D   document.sform1.id.focus();     
! s0 R- u$ v- g3 V% I* f   return false;     
1 T+ o% P; Z$ t9 _   }     
& C8 Z7 @& G2 `# P  } . q2 t# ?* J1 F. |
  chineseid = document.sform1.chineseid.value;     6 t+ w7 J# q, c. V8 x' m* s/ Z
if (chineseid == "")     ( O7 Y5 o; A" L- @+ [& r8 ?
  {     5 g  O1 T7 s6 A6 L* r3 C7 `4 t
  alert("请输入中文昵称");     
) j& Z/ ]# J; w) _; y  document.sform1.chineseid.focus();     , O* H3 C6 d) H/ {. @
  return false;     2 E8 O- _: y; y- `' L8 j
  }    0 G  M( \5 k: k$ C6 f9 q: [! v
password = document.sform1.password.value;     7 `1 [7 `/ v, P7 k; D7 Y
if (password == "")     : M6 f$ A) [$ f( g, O0 f: d
  {     : B6 D+ K$ T3 t2 ~& e
  alert("请输入登陆密码");     
( k+ h4 n% o* u3 O: I) M  document.sform1.password.focus();     2 ~+ v6 V7 R; C2 W
  return false;     ) Z* V: z1 R* ]" r0 \/ D
  }
9 |9 g  \; Z+ w: C password1 = document.sform1.password1.value;     0 |3 b; u1 p4 K5 W
if (password>password1)     6 \8 b  J4 J% [" K; Y" g
  {" e7 J$ }" |2 N+ H( _* t. y
     alert("重复密码与登陆密码不相同");     , ?5 H3 T4 @7 j3 `
  document.sform1.password.focus(); ' i. [+ C, S' _, Y9 v+ ], g
                                document.sform1.password1.focus();     
% a/ t% Q% m! p, j  return false;7 J8 L% p4 S1 K) _/ C  C
  }  " _& b& u( H2 e4 ?+ Q( R9 \
if (password<password1)       C! d4 d" K1 L& f) i: n, \" b& C
  {! a1 X, i% z3 H, z
     alert("重复密码与登陆密码不相同");     
8 Y1 g% N( M* j' c+ ~  document.sform1.password.focus();
5 q: C+ Y' i  p! p, I( N9 o/ H, ^1 D                                document.sform1.password1.focus();     
/ k; D0 Q- f* C+ @4 {  return false;4 G+ C" Z: x7 j2 O
  } ) m/ u+ Y  U: s! p. N( |
if (document.sform1.email.value == "")     
  _# _' V, D1 s3 k" q$ }! ~, b1 I  {     
  ]  F. l! l! S7 R$ {  alert("请输入您的E-MAIL地址");     2 p" \" m1 x7 ?/ J
  document.sform1.email.focus();     . k5 {# {3 a5 g6 I. K% f: i6 E* d7 a
  return false;     . j, i% v' H& w* [3 @
  }     
1 `+ B( K- h! M      
3 e3 g: e3 o: W8 ~ email=document.sform1.email.value;      
( l" w% k  O! X# d( F/ m emailerr=0     6 ^) Y+ u3 y6 G" s4 t% d, l/ W
for (i=0; i<email.length; i++)     6 Q/ S8 u' I* G6 R7 n8 W6 d
  {     
; \" ~; n$ Q( |) L- Y$ M  if ((email.charAt(i) == "@") & (email.length > 5))     
: _- [* v: s+ o2 ]& {   {     7 d: a1 a+ D! Q0 i% A' ?$ q* S
     emailerr=emailerr+1     7 N' w7 w( F  r5 {2 y
   }     8 @' t& g* ]7 M3 k( H8 s# E+ }/ i
  }     
0 ~2 W. }0 i& Q3 [5 J8 |, Q0 K/ _- b% K if (emailerr != 1)       U& i: \1 j$ ^
  {     7 V7 h! ?- d7 h% p2 I
  alert("请输入正确的E-MAIL地址");     
1 R) q* w, J! x- a& K2 B  document.sform1.email.focus();     
- X# p! p! z* T- }8 C7 J  return false;       Y  a3 h( R' n5 H
  }           8 H+ F4 e* ?+ y% q: ?6 r, f* N$ @) E
  4 W& C. R9 g7 y1 }# q) c
if (document.sform1.checkask.value=="") 2 q3 m. H$ Q  V5 O& D
  {
; M0 h2 P' u  q1 z2 X2 q) }8 \2 \& Y( R   alert("密码提示问题不能为空");     5 e  d* k, l$ D, I2 @( f# C5 c- H7 h
   document.sform1.checkask.focus();     3 k8 M- F; R( u' r& M
   return false;  
+ f9 y! Q6 G" t) l( u  }
& U$ n' k1 [. F, l" ~9 P if (document.sform1.checkans.value=="") 2 |. G7 c5 z5 M6 W0 n
  { , C: w  G+ ^+ g; d3 |$ A- H3 O
   alert("您的密码提示问题答案不能为空"); ; {7 X$ r8 I/ F
   document.sform1.checkans.focus();     . C( q" N8 J2 s3 J3 k- j9 }) B5 L
   return false;  
' T$ T& u& |& d8 R% `. H  }
& `# n4 _% e; @2 u& u# b return true;     0 G$ n$ \' I) d- |7 l; z# p4 S
     / n/ Z# T' `# l, E$ ^0 }
} + x- i5 l5 |& E) M
</script>

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