返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:( G  K  Y  w0 A7 ~! _5 p
<script language="javascript">     
. m0 c  x7 N+ p% Z  P9 W, ~6 s  tfunction IsDigit(cCheck)     
) o1 u8 o4 Z" _ {     9 I# \, ]! M) t. ~2 s# s) J4 S2 Z
return (('0'<=cCheck) && (cCheck<='9'));     
/ H, ^2 h  c2 D( Z" L }     
- E- D, Z6 _; Y" ^: e0 E     
* w/ r$ R, b; H% Nfunction IsAlpha(cCheck)       ^+ t3 a0 z  ~" _( D( h
{     ) d/ Q7 D- ?! c! W
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     : n  L- W9 Q. B% G
}              / y# y: J: t; l: ]; S
      
! k2 x. w: p# ifunction IsaNull(cCheck)         
6 h2 k* P3 ~7 _1 N0 l {          & l, Q2 j7 J( @
return(cCheck != " ")         % V7 e! S: R+ J5 @
}                               3 S2 Q# L6 o1 d! q% O
      
# f- c7 C( `9 N+ cfunction checkform()     
4 j( V! ^8 |" m0 K3 u{
  L  m' l( U/ \  T! `  id = document.sform1.id.value;     0 k5 Z* {4 a0 g1 z
if (id == "")     
& J/ O' ?4 y; w. M  {     
; d- _/ M4 ]9 c5 x* L1 d% ^3 O  alert("请输入注册名");     " X) N0 u. i, Q+ T
  document.sform1.id.focus();     " [+ ~, M# \- s& ~7 T# {8 o
  return false;     
, e7 O9 N0 }: o$ q  }     
6 I6 T* k) G2 {: `$ I     9 j4 a/ x- G# ?; u$ k5 [. U- ]
for (nIndex=0; nIndex<id.length; nIndex++)     : ?& x+ p. H& r, p" H8 z, z* Q8 X
  {     
' }% _# J( H' J& h# G  |( {  cCheck = id.charAt(nIndex);     0 O" u( P- q( W5 E! e) w
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
5 o5 S# `( `+ p( ]: D/ Y4 P! S2 i8 L   {     
& R; g2 w. w" j5 |   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     * k" N0 N. j& K4 }, \7 l; I
   document.sform1.id.focus();     9 ~( y: d& y+ m$ N$ i2 o$ v
   return false;       {1 c0 s5 Y( L
   }     * H# |3 z# l* Y
  }
, x# E! I% G3 U7 y1 P* Y8 t, @  chineseid = document.sform1.chineseid.value;     
7 t# |5 \# m. j' `3 D$ h if (chineseid == "")       B7 V# @! i% Q" U& j
  {     5 h1 Z  c  z1 L3 @% H
  alert("请输入中文昵称");     % e' E4 k! P/ C& P& `
  document.sform1.chineseid.focus();     2 _0 a! z4 O! i+ a! P& L: f8 ?) b* g
  return false;     1 p( {; P% y8 v- b- z; C% ]
  }    2 ~% ?; U* V9 o) @/ Y
password = document.sform1.password.value;     
$ [3 N+ m; n( K; \" c7 P4 ] if (password == "")     
% G3 R+ H* \* ^  {     
' t) [" b2 Q% |! |  alert("请输入登陆密码");     9 A% r4 H1 @7 `, I& Q  @4 E' o
  document.sform1.password.focus();     
; a2 v0 u  S$ n9 Q  U  return false;     - ~+ z' [5 s5 i3 b
  } * A4 _( @0 J( b6 ?- O* r6 Q
password1 = document.sform1.password1.value;     $ d! U+ ?8 R3 P5 X- r- w1 f
if (password>password1)     ! }  R; S* U' {
  {0 U$ e5 |# l: Z
     alert("重复密码与登陆密码不相同");     
6 Y# j( |5 a# V, D9 T" Z$ g  document.sform1.password.focus(); $ n$ J0 w  h1 f' N3 M
                                document.sform1.password1.focus();     
; o7 u3 Q( P& a& A$ O2 }, j$ _  return false;
) D# A. E* b- D- |  }  6 T" |! R$ N. U! p2 l' ?
if (password<password1)     
' s. ~! S' p) A( Y" o  {
- i9 r: {4 x7 J6 `     alert("重复密码与登陆密码不相同");       `! ^  ?7 E: C) n
  document.sform1.password.focus(); % ]+ \3 R! `0 D2 I$ I0 l+ T
                                document.sform1.password1.focus();     
7 F: ]( E0 W) o! y0 e  return false;
# X) e1 K# A$ _# k, [! m9 d0 e  } ' y6 M$ K5 m  ?4 D* z
if (document.sform1.email.value == "")     
! g; Q0 ~: q+ g1 B7 x$ o8 ^  {     0 F3 u* c8 e: ~: U& a
  alert("请输入您的E-MAIL地址");     
# I, L) I- V2 K5 z) r  document.sform1.email.focus();     + Y4 q" Z, k$ L) X2 |
  return false;     
8 y% _  d. Q# u/ [; U" K7 }  }     " x/ S3 {1 l4 }1 T; E
      - p7 @2 u8 e4 E* F! [; ~! r
email=document.sform1.email.value;      ) R! d1 U( Y' F4 T$ K# s3 f- i
emailerr=0     
. ^3 K6 L8 [- e8 j6 s& n* v( u for (i=0; i<email.length; i++)     
$ K3 F. [/ ]+ s: N. _" Q  {     ) i& e2 A' N3 k+ i$ ^' C/ o
  if ((email.charAt(i) == "@") & (email.length > 5))     
" S/ Y" q* Z$ L) R! K   {     , w# h( R: k% |* D" x9 v
     emailerr=emailerr+1     4 x( {: l. G" }" o" [8 F, V
   }     0 z# l% F- \6 U" T
  }     : \3 @: {, l7 S# N
if (emailerr != 1)     9 L! N$ y( Z6 P
  {     
% c. _  d2 p" N  w  alert("请输入正确的E-MAIL地址");     
9 D: D# L# @+ P/ U# f' f  document.sform1.email.focus();     % D) |  M1 C$ _# J1 X
  return false;     
7 B( y" Z- A2 m2 U" ~. n  }           % [2 a2 e# d' F6 `
  & X# }+ C& H7 b" i( v6 V
if (document.sform1.checkask.value=="") & Q9 s7 W. {( `
  { % h1 n- @* C  c
   alert("密码提示问题不能为空");     
  w" U) D" L+ a& g: k' A3 O   document.sform1.checkask.focus();     ; x8 Q0 ?; t* t: s+ b2 P* K6 S0 q& F
   return false;  
0 b5 Y! |5 S. x2 k  } ! r3 y# r5 f1 J% V& p5 i
if (document.sform1.checkans.value=="") - k- }3 `* I3 Y% Z( b: v
  { 1 c5 ^+ A# s  c" A0 {9 w
   alert("您的密码提示问题答案不能为空"); ) V4 H  h. \6 a( L/ \
   document.sform1.checkans.focus();     
% X4 G% y% [- L0 M! C   return false;  & c+ f$ A1 X  l+ J) J  [, [/ l
  }
0 _; T) c) b' } return true;     ) r% D/ ^/ a( ~
     9 t" B6 I4 B" |# S. n" G; Y# T
}
. D8 S& E; a; A</script>

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