返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:" y) k/ V! G- z' k
<script language="javascript">     
8 f- M! }; S' S9 h9 g+ ?7 Rfunction IsDigit(cCheck)     
! R2 }0 s" U3 S) ` {     
: z+ d5 p" R! M# }- U8 F return (('0'<=cCheck) && (cCheck<='9'));     
7 h+ @6 f  Q& v0 }/ K }     
, A0 g$ {. |8 ?# s     - a! L1 C% U/ y( j! U( N4 U) C8 y
function IsAlpha(cCheck)     
4 Y8 V9 ^- L. b* s; B8 X  b" | {     
6 v& X9 X/ U  M$ X1 `& G return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     5 J+ Z1 Q. c7 j$ F
}              
! X! s$ n. D6 h- l8 Z$ J      5 Z+ L) S$ C; a- V9 R
function IsaNull(cCheck)         
, {$ g) ?. F1 E2 `: p {         
3 ^) a: \  ^# S7 l& e9 o# f return(cCheck != " ")         ; Z7 D6 l3 A3 O1 V6 V) g1 M) a+ O
}                               ; b* o5 }  H* V7 w, F7 y
      
* y  U! w9 N; M  D4 L3 Tfunction checkform()     % ?4 Q. p5 A* B1 [) a
{
: m/ y! `6 l2 O3 U  id = document.sform1.id.value;       _& {4 K$ F, A; R
if (id == "")     ; A) o6 G; n1 ^* Y1 ]0 J
  {     
1 Y! r" f) }. J& r! r4 t  alert("请输入注册名");     
1 `- _3 k4 b, q6 w  d# I% z  document.sform1.id.focus();     
0 y2 X" _" _7 O  return false;     ; q( u" z/ L2 ~
  }     & U- V, t) i1 o( b) r5 b) D
     + q2 B" A* B4 [
for (nIndex=0; nIndex<id.length; nIndex++)     
7 P$ U' i- q/ n$ d4 D1 _: a0 X  {     7 s, y. L8 [% V0 D5 F3 J" N
  cCheck = id.charAt(nIndex);     
1 e$ _- m. Q) r5 U8 F/ G  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     2 s6 [" a2 b2 w
   {     
& u5 C9 |! c5 Y( [; h   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     $ L5 S3 j- \7 ]6 e
   document.sform1.id.focus();     
; z' W& g9 @) C- m+ l" t   return false;     . F2 ^3 L& B  }3 L  t0 ~5 h
   }     ) B: b" ], B- t0 g' Y1 |# U
  }
3 c  B6 s, s  o- K: P0 B+ x% D  chineseid = document.sform1.chineseid.value;     ; c+ p7 ?3 A; g2 Q- O1 m! E
if (chineseid == "")     
) ]- U2 y3 k: v7 m2 b  {     
+ O( _6 E4 o$ ]! y$ B) D  alert("请输入中文昵称");     & K9 _4 T8 v) m0 K5 B
  document.sform1.chineseid.focus();     
: L8 Y; I5 S6 h- l* r  return false;     
% ^6 D4 k8 z% R$ I" a$ f/ d5 E  }   
! ]  {9 ^, m7 F4 N$ {3 P password = document.sform1.password.value;     
* R/ @/ c4 m/ F if (password == "")     
( m# c5 U8 z/ k9 N- P  {     5 f7 Z; x- H# H/ q/ }
  alert("请输入登陆密码");     - s+ k0 O9 Q7 U+ B: z, q5 j' z
  document.sform1.password.focus();     
- Q( E& g/ U- c' `$ l+ n  return false;     2 D- L% j) c, m, r
  } . d+ C! b. Y9 v8 ~  g0 f& U
password1 = document.sform1.password1.value;     
5 A- S% l( Q, E; X5 @ if (password>password1)     
8 f6 O5 J% j/ ]: N  {
  ~: f! H" t+ G' V8 |     alert("重复密码与登陆密码不相同");     ( T3 S% }7 H; J5 a  L
  document.sform1.password.focus(); 9 P- C  m8 r. {8 g, }& L
                                document.sform1.password1.focus();     
6 B3 ^& c6 G0 y. Y3 o& d% e' U4 q5 d# w  return false;
- H6 @0 E" j5 q+ [  }  
7 S/ @. I6 X9 ~) z8 L3 ~( {( z. r6 Qif (password<password1)     # e+ j( Y* H; }: J$ @
  {' ^2 J' C6 e  `! ^& ?
     alert("重复密码与登陆密码不相同");     
% Z' X6 t; F! {3 S  document.sform1.password.focus();
0 a" S* {3 N" h1 h1 K2 s! \$ n                                document.sform1.password1.focus();     ) j4 v2 D( a  |7 a
  return false;- c; ]+ a9 c( j" h: T- m6 f$ N4 n1 E
  }
2 l! j, \; F( g. e if (document.sform1.email.value == "")     3 d1 D5 u: u% r  H/ \
  {     
' S+ d  _4 q2 [* u; o- a& x  alert("请输入您的E-MAIL地址");     " y; k. k% I- S0 i1 X3 k( {
  document.sform1.email.focus();       E. N9 z! ^4 B/ ^
  return false;     
. o8 f* y: ^$ V: ?! z: \* V& Z  }     / i* O5 o4 l- d" F  c- v. Q3 N
      
; v/ q# Y! l/ R6 a email=document.sform1.email.value;      
1 ]7 @' g" Y- B4 u6 p emailerr=0     
$ Y0 i3 P, V5 g& E/ J for (i=0; i<email.length; i++)     2 V( D4 ]9 f, Q0 ~& K* P" z. ?
  {     
& g7 ^4 K  P; Q9 C! A  ]# M! [2 r, w* j  if ((email.charAt(i) == "@") & (email.length > 5))     
0 e7 c+ q" Q/ |/ w! o   {     
3 `$ O# c3 b* n) j/ t. L% }     emailerr=emailerr+1     
5 v8 j- {" h8 T" Y: o2 X1 B9 @( l" x   }     9 {& P, k* t: V: ^  U8 s4 U
  }     
! S2 G+ t% d: o  n) K; ?  E, ~ if (emailerr != 1)     $ ~8 V) b4 N# y% O  S$ z& ]  I( a
  {     
3 S# W7 a: y. ?4 J" R5 p' J) X. x6 s  alert("请输入正确的E-MAIL地址");     & v1 I/ |" v% \. s. j' f* _" h
  document.sform1.email.focus();     
* O7 O# j( |, c  U( {8 w  return false;     ) i+ t+ Z  I  V& J( I
  }           ( G3 i, j. F" ~
  
/ D0 |! K4 D1 a. J$ H7 Q4 |8 W& o if (document.sform1.checkask.value=="") 7 y* d1 F4 ]; o' u
  {
2 V% p* C& g2 H+ y   alert("密码提示问题不能为空");     " |- J9 [# h' ^* J
   document.sform1.checkask.focus();     
: g$ [+ u9 M& d; q   return false;  8 W, o, o+ E% h6 H+ e
  } 4 p  o& x6 n" b5 Y( `' h
if (document.sform1.checkans.value=="")
8 t9 g& S: u* X, P  {
( w$ p  H+ y9 t5 p+ ^  E& Z1 u/ X   alert("您的密码提示问题答案不能为空");
3 u1 S( ~( o0 a. R   document.sform1.checkans.focus();     9 i$ ^. s' A8 E/ Z7 {
   return false;  
- g9 t( I! V4 d2 o( C% B  }
: g4 p) \2 Z% `% [ return true;     $ }$ @/ f6 x' Z) D# W
     ' P# w* ?4 ?  U
} * J" l* X+ x' }& X( a
</script>

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