返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
* w. f% ?; j; ]' ]8 X$ O<script language="javascript">     
$ c& Q9 p# C0 g6 P+ l% dfunction IsDigit(cCheck)     
7 L  `# V, q+ v8 p. m8 x {     
7 Y: C, x( y, y. b0 y return (('0'<=cCheck) && (cCheck<='9'));     " e! p3 h9 W9 |- N( l8 Z
}     
$ b) o2 `8 S0 Z2 |! L: \0 z     
* j" X. V: s. r( ifunction IsAlpha(cCheck)     9 `0 {8 U6 Y( L$ o
{     2 a) ~# z2 |( k0 s% K* k
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     8 a) j; R- o: F( ]
}              
+ Q) J( r( _9 M. o6 f3 M- @' E- l      2 N2 E8 ?% K$ `; _) k. r$ H
function IsaNull(cCheck)          4 Z8 s! L0 J+ \
{          + u6 V- G* l" m  `  X: w8 M
return(cCheck != " ")         8 u# x, l& t8 y. t, R
}                               * _! \0 B( ?2 Y7 `
      
) [* E' w+ E  g6 ~function checkform()     
6 p: q. q* P( u{
' p" Y) @. }2 y% p1 d; V  id = document.sform1.id.value;     
" h0 _7 A* k! ^' x if (id == "")     
: V( H# _: [" R0 D# `  d& z  {     - y, T% E  n* l& W  j
  alert("请输入注册名");     
- C& U: M/ J3 Z: N/ X9 u4 u3 Q  document.sform1.id.focus();     
0 U5 C4 N8 O+ w+ I3 Y  return false;     % v  w1 r& f9 t9 j8 g5 @! x  l& A
  }     
& R" R0 Q1 k  C) g3 ~: L     8 g9 v& `6 D' S7 Z$ W& A5 ~
for (nIndex=0; nIndex<id.length; nIndex++)     
# _, R5 S5 J$ l2 d" U  {     4 O) j4 r; Y7 A; D9 {2 C, C& W
  cCheck = id.charAt(nIndex);     8 o% {# w9 b& \+ n7 s: j& r& @; U8 ]( W
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     " z4 X3 T' D- P# r& q: k$ R3 j
   {     5 ^+ D4 x7 J: H5 ]+ O
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
3 }" @: t# k- \4 q) |6 B   document.sform1.id.focus();     
0 u& x8 \5 T5 o* y* K  D6 ~   return false;     * n; b" L7 y& r' m
   }     . p. @! V2 V, O& G
  }
8 L9 j# q/ f5 W8 P8 y/ u) X! ~  chineseid = document.sform1.chineseid.value;     # h; ], s3 F8 Q- e- P( P
if (chineseid == "")     
$ b; S: c) s2 ?3 X8 o7 }+ B& {  {     0 R3 e: z. m; j( @* r
  alert("请输入中文昵称");     - g- ]+ `, a, m1 u
  document.sform1.chineseid.focus();     4 _* C6 C/ O1 K( S' b
  return false;     
8 R/ u' [1 p% @  V+ x& P, r# @  }    ! ~- j( g* ]& ^- C) D
password = document.sform1.password.value;     & y4 E* y3 v6 F1 ]+ g, l
if (password == "")     
5 D# r' e. a8 y  Z! j( S, {. a  {     * W' q9 ^( g0 [( S" Y# L+ G
  alert("请输入登陆密码");     ! k) l1 B9 z0 E
  document.sform1.password.focus();     # m0 L2 f) c2 [
  return false;     
9 ]8 `) O# ]. T* H) `. W0 i9 a; J  }
& M" ?# q6 X& R7 \ password1 = document.sform1.password1.value;     1 |4 d- {8 y5 z
if (password>password1)     
$ t% v- W. y5 e) w) C  {
) ^0 \5 o; A+ y+ V     alert("重复密码与登陆密码不相同");     
9 M& P, [7 `$ e  document.sform1.password.focus(); * A( h. A3 `' u5 J, R, T. H" @
                                document.sform1.password1.focus();     
* f8 Z. |* s1 \  return false;- o# n; g* w, m- ^9 ]
  }  : p) m5 x/ }: `
if (password<password1)     
2 m4 O2 [; w# I4 F# Z; I) w  {
" s) N2 r% L# c- s& w% D, N, C# C     alert("重复密码与登陆密码不相同");     & _# [! y8 z" D+ V- B# f; K
  document.sform1.password.focus(); - }1 `& P) c0 s7 f* d4 _, m
                                document.sform1.password1.focus();     
& A% q0 u' \6 ^7 B' L2 l  return false;3 L% ?! `' M2 u; W) v' n5 q
  } ( Q8 V6 ?6 Y" E/ d6 M  ?
if (document.sform1.email.value == "")     
8 h: m5 s; F7 z) V: ?% w  {     " @8 P- M4 w8 Q+ j, Y8 @
  alert("请输入您的E-MAIL地址");     4 ?- ~2 ]8 H# O$ k
  document.sform1.email.focus();     9 D6 B6 A, [& R& N% i0 ^
  return false;     / o! }5 j2 A8 e0 P3 W* X
  }     
, L% c2 I4 S9 @$ C8 i# ], u7 m: |      
* H# S% y2 s2 Q# ~' }2 s9 S email=document.sform1.email.value;      * o# [, l* J8 H9 i: S  {
emailerr=0     
* Q/ z" U1 M5 M) o% d. X& S/ F for (i=0; i<email.length; i++)     
" e  w) w4 A2 p: W8 x; Z) T: V  {     " J1 {5 S9 D8 X! g- B
  if ((email.charAt(i) == "@") & (email.length > 5))     & d& O3 O8 [% _: L
   {     0 J# b' K: I, S3 o9 O# {
     emailerr=emailerr+1     
% f2 L8 _, W0 J0 G   }     ) V6 o; ~; J% [, Y0 i% ^
  }     
% e/ f8 e- g2 k if (emailerr != 1)     
. L* [2 O: b  s9 x# K0 H  {     ) {0 @! i$ w% i$ T7 h% q' d6 v
  alert("请输入正确的E-MAIL地址");     
0 S# }& j$ _( e0 g) i/ o  document.sform1.email.focus();     
, c) o9 a2 Q& M# o9 t9 q  [  return false;     
# t( C9 p% d. c5 r( S' h  }           ( V- Q3 z( o& H$ I5 j! Z7 z$ U4 _; W
  
6 B8 P; V1 Q* L( W if (document.sform1.checkask.value=="")
" _0 F  O7 _3 h  { 1 s# Y/ q; \* t( c* _* a
   alert("密码提示问题不能为空");       s4 s- I$ w1 Y% N& u$ K% q- w
   document.sform1.checkask.focus();     , o* b6 B; Q1 W+ P' N! D
   return false;  ; D$ }) ~  n0 p, _/ \( X
  }
4 N$ F$ ~1 a6 }2 ^ if (document.sform1.checkans.value=="")
% U4 I1 E* E; E  { ( ?; A) B" R% {8 M8 X
   alert("您的密码提示问题答案不能为空");
! O5 q6 `" i' j   document.sform1.checkans.focus();     
) K. x) ~2 ]2 j  F/ m   return false;  
/ |/ p, R. R, t2 h+ M$ P  }
( e8 }% c& w" w6 s% r% f0 m/ J return true;     
5 |! Y: S- M* ?3 @0 t6 G4 ^3 P8 d     4 O1 m5 z! L4 T8 U& ]- R# \6 ^
} 5 [9 o  E0 I# b/ ~# E5 J
</script>

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