返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
. V0 h$ ?) J& t9 O1 U<script language="javascript">     % n; A' d2 O8 }7 j7 P8 k
function IsDigit(cCheck)     0 q% w: N1 R8 U+ \; o0 N6 E
{     0 R% Q& X: E% ]% Q3 m
return (('0'<=cCheck) && (cCheck<='9'));     
4 i5 G: H( w+ Z& {+ [( }  V% Z }     ) K* w& m, ~8 T7 s( \6 k9 f
     1 W2 r! g, p9 y0 E: g
function IsAlpha(cCheck)     
5 h# V9 K5 t( c! U {     
6 a2 h0 g, v. b$ e, T! o return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     2 X( x- l6 v: G5 H- a& X
}              
+ q  U) J8 q2 `) K% F( {( i      0 e+ F7 V) Y" Y% U; @/ k
function IsaNull(cCheck)          ) m+ e3 p+ l; X' O
{          8 w* y. H8 ~! }% ^* X
return(cCheck != " ")         . ?4 G$ |; H; R; d. G3 P6 w
}                               . W/ c% X2 n$ K' O. {$ J% O& F
      : h$ P/ i+ ]- Z  ^  r1 _8 [, x; ?
function checkform()     
7 L* K9 n! b3 \{
! \1 t4 l0 f9 e( u2 ?6 Q  id = document.sform1.id.value;     3 D% `4 B4 p0 |9 ]% J
if (id == "")     
' b) S6 i" s# G; ~  g  {     6 p; v8 G/ |$ f  y& k: s+ h
  alert("请输入注册名");     : J; D2 y! U5 J9 o7 t& Z8 P4 l# `
  document.sform1.id.focus();     
: |, M: L2 ?: {- Q5 x2 k5 ?* J* X4 t1 [  return false;     
* ?, y% f9 N3 ]  }     * U2 g9 d; |. e  H, u6 w" ~0 a2 b
     8 Q5 X+ E* W/ b/ q3 N4 B# F
for (nIndex=0; nIndex<id.length; nIndex++)     " s# u8 k5 `, u/ S' N
  {     5 O  S2 l' {  ?( c% M
  cCheck = id.charAt(nIndex);     9 L5 k. H1 `$ O; w" Q6 f
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     9 v& \9 T1 \( }. ]: H* ?: ~
   {     " @% O6 X* E- d+ p& _. O* c/ ~
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
* ~% U* p: H8 F+ `! z   document.sform1.id.focus();     
5 O3 u8 c9 n9 N# K6 M6 D) R2 e   return false;     / {) G. m' O  B% J
   }     $ V5 N, k9 @% @- W6 ]6 m5 T: C1 w
  } ; O+ d$ {' Q# E& v) [5 `
  chineseid = document.sform1.chineseid.value;     9 s, Y  F, J1 C. p1 K; C
if (chineseid == "")     
# H: |# C9 ?7 ^$ T9 h  {     
5 @$ {5 t3 o( A6 n  alert("请输入中文昵称");     3 f5 E. o3 e4 E
  document.sform1.chineseid.focus();     
$ M( h6 W4 w" F7 i, P  return false;     ' I/ x: [; c$ I  {( q8 h
  }    2 u) k; J; h5 K5 B4 ^
password = document.sform1.password.value;     
3 W+ S* k7 d( [2 u2 K if (password == "")     
/ ^- o, P& ~3 C& K) j  {     
- Q* Q3 X: L; b& c  z  alert("请输入登陆密码");     $ Z! F/ T& T: }/ V. a/ G$ D
  document.sform1.password.focus();     
; w6 b& k3 g1 y% v  return false;     
7 K& o- y, R$ @+ _  }
+ _1 N. d* Q5 A* p" J password1 = document.sform1.password1.value;     / C9 u0 g+ ]2 S& ?6 ^& y
if (password>password1)     . Q7 Z$ r5 Y8 Z
  {
4 C: ^3 A2 M7 h! `: ^& b     alert("重复密码与登陆密码不相同");     
, I3 p; y  @* l, U  b0 ?  document.sform1.password.focus();
! _; l* L) F/ z6 W/ L6 Y                                document.sform1.password1.focus();     
- p5 l: F0 W; c% \  return false;
! v# A" _8 G5 M/ |8 R$ L  }  5 U/ g, @' D" \& s
if (password<password1)     7 v7 V* Z5 P  `8 L$ h
  {) Z9 t, @: h& o7 w
     alert("重复密码与登陆密码不相同");     
7 f' r6 z/ Y, ?! m* O9 l  document.sform1.password.focus(); 7 |7 e- @4 ?+ k
                                document.sform1.password1.focus();     
3 v/ q' }2 O; F5 M# W7 `4 Q  return false;( o* w9 C6 h! K1 ]
  } 0 S1 v# w% t( c' ^) D
if (document.sform1.email.value == "")     
7 d& q' A- i+ j  I, f  {     
+ k. o6 ^9 d8 r, v  alert("请输入您的E-MAIL地址");     2 z+ B$ r. e$ K- G
  document.sform1.email.focus();     
4 D  G3 W" u9 ]6 J: `4 \2 ~) |  return false;     # e6 n3 A( Y* U
  }     % j7 A( J/ i6 r4 a. M  {
      
8 W/ @- x, U# s# t8 H: u email=document.sform1.email.value;      
- [- h  u5 b' f" J0 \ emailerr=0     0 w% [- J7 j+ _4 _1 D7 Y* V
for (i=0; i<email.length; i++)     
. O' Y3 l/ T1 `# V$ W- x- z6 K  {     
3 y9 ~' m# O% X( B4 s- @, T( H  if ((email.charAt(i) == "@") & (email.length > 5))     , D' a5 e( h9 D. N4 J7 L
   {     
/ I7 l; M4 f2 d$ }, x, ]     emailerr=emailerr+1     
& A- A5 _' n" N6 p8 [4 T: D1 a; o3 ?   }     
3 m9 h- `) x6 M: a: N3 l" V& U  T& ^  }     2 `6 @2 ~7 `+ X- S' U. e
if (emailerr != 1)     * e! z+ p$ e! M& _) h
  {     % u  S3 C, H$ U8 i$ ]5 B" q
  alert("请输入正确的E-MAIL地址");     
  k7 [4 e# j- g  document.sform1.email.focus();     5 k" B) q; a1 S; p- B/ C) G
  return false;     
% e9 i9 q" k2 y  b8 P7 ]  }           : D+ C' [5 e, O' b% f; P) V/ b3 I1 ]
  
4 s( m" C' w! @3 i if (document.sform1.checkask.value=="") ' p# q1 q& d$ ?; C) f2 Q# M3 J
  {
% R0 V9 V- |/ l6 q/ j   alert("密码提示问题不能为空");     " ]2 E- A' `9 a3 A( b7 v2 X# u
   document.sform1.checkask.focus();     + `1 \/ M, J3 G
   return false;  # L/ U  d" z3 s; n  H
  } 9 `/ t1 Z2 f. [5 {
if (document.sform1.checkans.value=="")
1 K2 ?1 Z6 Q3 b/ f" c: W( }  {
3 ^4 }' S: `' \* ?7 O   alert("您的密码提示问题答案不能为空"); ( D& f0 L! B3 J3 p/ v% ]0 o, l9 R
   document.sform1.checkans.focus();     
9 W, ]; i9 u. r4 q. i* h2 b   return false;  ( V' ~. b% R4 I+ A
  }- Y* n4 t. O9 @6 P9 K# a
return true;     
% ?: A) `& t5 d     + [( y. q* [8 g6 C- y6 M7 b
} 9 i! `  {7 N. q( K3 S6 c6 d
</script>

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