返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
% `+ f' E/ j. P$ s6 z& a4 N; R# U3 J9 J<script language="javascript">     5 E. d  z4 c' k
function IsDigit(cCheck)     
5 {# P& H& d+ H3 r* |$ P  g {     
" q. K; D' ?& r6 E return (('0'<=cCheck) && (cCheck<='9'));     0 W" r6 P) Q5 Y# y0 O" X' L* Z
}     # a; [  x, l: G5 D8 w7 P
     
; \4 ?0 X( X: s+ t' t6 }% c; b. S& Vfunction IsAlpha(cCheck)     
' d. L# Y% r0 [8 M/ @2 G1 O {     
+ W# L4 E) R& _+ b8 |4 L return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))       O. J4 k! N0 ~6 M4 N$ J! @0 v0 U
}              
+ T7 h9 S' |! h6 P* Z+ z      & ^* n( Q/ r$ ?, `% |( U4 D* U
function IsaNull(cCheck)          2 f% W! |+ a! G+ J5 z
{          * P" E8 B5 G/ d$ |; k3 M
return(cCheck != " ")         
* G9 U3 o% f5 z# J2 u* C, h7 v- G }                              
2 |  m/ Y4 k* }$ k      
0 f$ u$ m# }( m" F! gfunction checkform()     & }- L! a9 ^5 s$ C$ @
{ # U( L0 h8 _2 ~, t. J
  id = document.sform1.id.value;     $ ?8 B/ g# [# V# r: P) h
if (id == "")     & D, u2 R* j- ^8 k- I: I0 b) W8 O
  {     
* J) g! t: w7 K) w/ t8 }0 X1 r  alert("请输入注册名");     
: N% R$ |  j" a, M  document.sform1.id.focus();     
/ Z  }2 h1 B! V! ]! a! R  return false;     ( h- o7 {1 v& E$ p
  }     
7 Z" V" Z7 a* ]" J4 H4 x     
9 `" ~( N# r9 n0 c for (nIndex=0; nIndex<id.length; nIndex++)     
8 b4 M% Q  a9 j- y1 M2 \  {     
* L$ I& ?( ]1 t5 O% a& z$ Z4 o  cCheck = id.charAt(nIndex);     
& a: o2 o: d& c4 U  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
. V' Y! E5 A" T( P  H4 e  D   {     : D$ N+ _( p- ?% L" |+ r' \
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     2 D! [) X  L7 [; m& k- l( c
   document.sform1.id.focus();     . F& ~8 ^! D/ P* c( d3 |1 [0 @$ I
   return false;     # |0 \3 T' z( y( h( t* G+ x
   }     
9 Y/ d% |' E9 F0 L  }
5 r8 W4 p% v" |  chineseid = document.sform1.chineseid.value;     
+ a8 F. _) G3 A if (chineseid == "")       V$ b4 h4 d, h1 ]' _1 r
  {       b+ G, S3 q0 f% i' |
  alert("请输入中文昵称");     + P: W) y( B2 E9 i
  document.sform1.chineseid.focus();     
4 S( l+ Y9 ?' t' H8 \/ a  return false;     . \2 ^) h: D, `8 @+ i0 y7 u
  }   
) Q5 \0 B% d" A; `: R9 N password = document.sform1.password.value;     
8 \/ u; y4 E. }6 u7 t) T/ k if (password == "")     6 D! b; r8 G& t4 V
  {     # P+ \4 M* U( l; l
  alert("请输入登陆密码");     & q1 R2 X4 n  R  M7 ^
  document.sform1.password.focus();     
: @* |1 b' G0 H( K9 L4 Z9 m  return false;     
9 I  A# p0 m) I% p' v  }
7 D* m2 `$ M) y. \( S password1 = document.sform1.password1.value;     & t$ G/ y! P) w( r) t
if (password>password1)     
! K; o: i' Z. j5 Z( J  {
7 J+ y4 {2 f& U" f; l- w5 v& `     alert("重复密码与登陆密码不相同");     
6 F5 B. I  c3 t9 g2 h, {2 a  document.sform1.password.focus();
! Q' S( ]8 X! }4 `3 ]$ W& [( ?                                document.sform1.password1.focus();     
1 F: r2 Y8 W$ u  I  return false;
& [* e! H' m- m, @6 N/ i. j+ h/ L3 n  }  9 ?) h: \8 f/ `* |4 q
if (password<password1)     
2 i! d6 b; @* \6 e' D0 W- V$ Z  {
/ i" m* g# [9 b/ ?* H& d     alert("重复密码与登陆密码不相同");     " n+ ^  z7 n8 a8 T4 R8 z. Z6 z
  document.sform1.password.focus();
0 @+ J6 y/ a8 O0 c                                document.sform1.password1.focus();     9 C2 p8 e* N) p: _
  return false;
% V" w" Y6 q: z5 D  V2 N$ H- e  }
% s. o& e) T7 A1 z% o( t. Z5 r if (document.sform1.email.value == "")     
+ j, h! b! D1 O8 q! `% N  {     6 c& W( R/ e: f3 g% l
  alert("请输入您的E-MAIL地址");     
/ R' S% z  y) U+ z  document.sform1.email.focus();     
4 r, Y+ v7 E/ D; s  return false;     
, S/ F0 c3 Z6 M/ b  }     
4 x, G  G- u5 ?2 Y% T      
( O/ D- y# \) R: f6 U7 v+ H0 f email=document.sform1.email.value;      $ a& t: V; E) ]& J
emailerr=0     ( Y/ s4 z" f( g1 \& _* [: m
for (i=0; i<email.length; i++)     
0 \1 U  U. f( x$ z  {     # ]. C1 l. n8 y/ ]  w/ A" b
  if ((email.charAt(i) == "@") & (email.length > 5))     6 Z6 n: b5 f9 B+ e4 Z
   {     . f$ I! A; m6 w+ |
     emailerr=emailerr+1     
2 J1 m+ c, T* M" k   }     % F# y1 H' a. z
  }     . e6 u3 E$ p! J5 j
if (emailerr != 1)     
. J, r4 \  u' @  {     7 d3 K2 I* i+ O0 s/ ]
  alert("请输入正确的E-MAIL地址");     
% d3 W: ]2 K5 M: N) B: S  document.sform1.email.focus();     
$ ?; O4 h# f6 s: G' t  return false;     ) T7 O3 p0 B' ^1 a+ }/ F, r* U
  }           
9 E; Y7 I$ ]( n) ?8 i7 B: s  r; ~  
* h$ A6 r3 Q- G4 G( l& A, O, Z if (document.sform1.checkask.value=="")
. R3 a! q; I0 J) q( A  {
& e0 d7 q4 C! g2 n$ g5 t/ z+ G   alert("密码提示问题不能为空");     
6 w6 b! k. c8 b3 E   document.sform1.checkask.focus();     
4 ]1 j) m: {- J; b. ^3 i   return false;  
$ {) u, z9 b( N4 E9 R, V  } # W9 n; d7 i. ~# Q' L
if (document.sform1.checkans.value=="")
/ I0 p2 C& D" b: B) p7 l7 M& r' X  {
# C5 D" _  w" I+ E1 q* @   alert("您的密码提示问题答案不能为空");
/ ]: |6 v( c" V   document.sform1.checkans.focus();     8 J+ e2 m0 N- g& L$ ]4 F
   return false;  1 U- y; `5 Q7 g, n* J5 @" b: V
  }  M; t6 R. x9 x( ^3 g- Y9 L& ?
return true;     
) o- I4 X) ]# V  h1 M, g     % y/ n4 Q$ Z: h3 v! K; m1 G4 z
} 2 O- u- F$ H/ P. ]8 n  }) v6 P
</script>

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