返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:7 o1 |. d  E# K  F# `) m' A1 z
<script language="javascript">     
: a" c* k6 {8 Dfunction IsDigit(cCheck)     0 [# L6 b% |" w$ o1 j3 d6 ~
{     1 B' [2 z# U5 y' C: U2 i$ O# `
return (('0'<=cCheck) && (cCheck<='9'));     $ r, N8 V" R& [) u8 O9 \
}     
) s* E' J1 M3 q     
; I+ j% {0 q3 d4 n3 C( g% Zfunction IsAlpha(cCheck)     5 s' }# @/ v: {2 J9 o7 i0 G; Y
{     
  k) X( _" E! J" ~) f return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     7 r! m+ i/ [' z3 L5 m) A
}              
* A0 V/ X/ _2 O/ K- k' t      
* m( ?; e) B' t( U/ P7 L- Jfunction IsaNull(cCheck)         
: ~5 o+ L  M1 O7 V: j( x. E  X* ?, y {         
0 c" K$ y5 H7 i2 M2 F0 Z$ ? return(cCheck != " ")         
$ [5 z9 |' |+ I) O, T3 y }                              
5 c* Z4 {- `% G0 |7 }$ R5 g      # ]8 n) V1 R" a7 m
function checkform()     & p; s) Y0 e8 N( V+ G: i/ N" t
{ 0 \  n5 F& _; l4 y, v
  id = document.sform1.id.value;     0 U; O& y+ [0 S6 s" k: c& y
if (id == "")     
4 c- d& \9 Q' ^' A! b0 W  {     
6 q9 t, E, U3 u( u7 `% b  alert("请输入注册名");     
  h# e! h- r* J* y0 ^2 O  document.sform1.id.focus();     
6 M, X8 h* K8 ^! n8 D8 n& J$ R  return false;     
6 [) v* R. A5 ^  A  }     
: M' x! y" x8 z, v! j  r. Q     + x/ J7 M  p# D  I. c3 \% ?% ?
for (nIndex=0; nIndex<id.length; nIndex++)     8 C) F6 O: u$ W9 y' b' b
  {     ; B  `1 l3 z- @; e
  cCheck = id.charAt(nIndex);     4 ]# U) l4 P' S0 y: m8 t
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     0 {9 B, U4 d8 Z  N
   {     
1 i# F7 v1 c4 M   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     3 P) G0 J: Y( \$ Y4 J+ N; C
   document.sform1.id.focus();     - t- J8 ~& a2 H
   return false;     
8 g, `8 A. K, Q   }     
' s5 G3 C' m6 f! p& N  }
- Z/ ~# k& \4 _8 O8 L1 J  chineseid = document.sform1.chineseid.value;     1 m; n" U( ]4 X* l3 a4 k5 x
if (chineseid == "")     
) G& n0 o! N, O% e( y  {     
5 M+ M/ x: j4 F' H( D% U+ w; U  alert("请输入中文昵称");     , T, A8 o/ g/ X% ?5 r, ?
  document.sform1.chineseid.focus();     + l- d3 ^5 B1 @$ C; O- }
  return false;     $ f$ y, |6 k! N. F+ B& ]6 \, F$ I
  }    / A6 J. Z/ [, l: x2 N; H
password = document.sform1.password.value;     
% r8 Z5 s$ E2 K7 l! I1 ]0 G9 s if (password == "")     - u& M; p# M; o
  {     
. t; J- I( M. B$ A0 U# ?  alert("请输入登陆密码");     " M) t4 P2 A& G- n2 ?6 A; G7 W# W
  document.sform1.password.focus();     
9 N% s  M# ^) x  E# O  return false;     7 v; |+ P' t2 V
  }
% F( A# D" h0 O5 M! Z) i password1 = document.sform1.password1.value;     
( i; Q4 _: E& P  p6 c' X5 | if (password>password1)     
- A- w1 g3 A; k6 o( q* c# x9 z" f% x  {  D6 p5 A+ k/ ~8 b7 W! J
     alert("重复密码与登陆密码不相同");     
5 L0 h+ }1 ^& i0 D  document.sform1.password.focus();
( P! E- i, T7 v9 r4 Y7 G$ X                                document.sform1.password1.focus();     
; x4 a, T$ r, F2 W  return false;
. o/ h* l* q- g$ I. v. d2 d1 {  }  & b( Z' ~% D  Q% v5 I7 O
if (password<password1)     
( f& i, |! M! l5 L0 V9 L  {7 A" r4 l: N- D( ^# @4 s5 G
     alert("重复密码与登陆密码不相同");     
5 j2 g; Y# S  Q5 c  document.sform1.password.focus();
( ~' z2 F1 G5 a) C) b. \6 Z                                document.sform1.password1.focus();     
; p0 E% u7 ?" R8 d. U) ?  return false;- |7 b; c  e. h) J1 D4 k
  }
) M7 l6 X  Z% h+ P$ Z1 i if (document.sform1.email.value == "")     
( {, ]% w- M: a6 f8 O* g% ^* t  {     ) s& h/ P2 _) t, a4 W1 Y( K
  alert("请输入您的E-MAIL地址");     : T! ?2 U2 B4 v( ?; i: z
  document.sform1.email.focus();     
( T* }, }  W% P9 Z: }: y: R- M  return false;     
; H9 p; @. d2 l2 W  }     2 m1 P* j( [# R+ w  p# k& C: e3 K. t+ m/ }
      6 W) t/ u8 }6 s/ S# e
email=document.sform1.email.value;      ) H$ J" y$ W" a! o; f0 F8 A
emailerr=0     
1 l% c" m- \4 @ for (i=0; i<email.length; i++)     
# ^3 G3 R% m; X& f- f" U5 Z( V- j  {     ; s. i" C! j# l% I3 N+ ^" Z
  if ((email.charAt(i) == "@") & (email.length > 5))     
) o0 I  A( @& r7 p, j7 M0 }   {     
3 }$ \" s5 M5 L4 }     emailerr=emailerr+1     , X' x, ~* {  ~  [; m
   }     ; k: c8 i7 M5 i+ D* Z, n2 D
  }     
% q# D$ z3 t' d if (emailerr != 1)     
) [: _; U$ L. g. O' G- {# s  {     
6 \& o  R. g( B9 J: z0 H4 a. W  alert("请输入正确的E-MAIL地址");     
8 D8 D: B+ {4 j/ B4 _0 R" g* Z2 h  document.sform1.email.focus();     # y# m, H% e$ A4 [6 d$ _
  return false;     5 Y( J3 l: U" Y4 S  i
  }           
& c, E+ M- g9 v2 s( h* q    W* |- H4 G# z1 {
if (document.sform1.checkask.value=="") * m  k0 R, s# C  u7 B# M
  {
  H) D2 ?% Q/ _' t. ~   alert("密码提示问题不能为空");     
4 ]- l' g. b; v) W) N   document.sform1.checkask.focus();     $ Z  m6 C% W+ ?: P$ ?
   return false;  
' Y) g, f$ t) Y  }
! {2 I, y, S: E% U3 L if (document.sform1.checkans.value=="")
4 B0 S$ R$ W3 _* T4 D% U  { 6 c+ J* N1 ^9 s6 ~" }
   alert("您的密码提示问题答案不能为空"); ( G% v: k# M6 T% Y. z4 T/ c7 }! }
   document.sform1.checkans.focus();     * F* n4 X9 g$ m, _5 u$ h
   return false;  ! r: V" A" `# B8 k. u
  }/ i2 O9 z1 T! ^) l
return true;     9 I) c3 K$ d! R! A. j$ X4 a) w
     
, j0 S8 y& [" T  v  x  U}
: S: U& k5 V( b0 y* ^% Q) f</script>

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