获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
* [! Y2 b, ^( l0 y<script language="javascript">     ' T, F# y: o' g! G  D
function IsDigit(cCheck)     / A3 }+ A) ^3 b% D
{     
* J; G/ o. _' o- D% @ return (('0'<=cCheck) && (cCheck<='9'));     
* Q4 D8 J3 {- N9 D9 T }     
4 ]% ]0 }- [' H     ; a9 W4 R9 s7 W) \
function IsAlpha(cCheck)     
1 D2 Y. E2 _: Y; ~/ n& X' e {     
. E, k- }6 Z: J3 }, ~ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
- J# ?3 Y  ^& b% y& P  t }              . T6 m$ D$ n  D0 ]; C* u
      
( D! X/ |- z3 V& ]! w8 ^6 W& r9 pfunction IsaNull(cCheck)         
/ k  s! {6 T. R( M: @& M0 u {         
( w$ J1 a- c; x" o' s return(cCheck != " ")         
+ E' w+ o. l. w% _) V" g }                              
1 Q( V! i7 E& n) ?" g& |' ^: N& i4 T      
: I) @' E$ A2 _* p8 P, b; dfunction checkform()     
! b5 I% m/ H, a4 y/ |# o7 K$ V{ " M8 Z, e, v% h8 V' s/ c7 Z7 R! l
  id = document.sform1.id.value;     " f, _7 m* B; \: r/ p4 _
if (id == "")     ' [) p3 X4 l: ]! D& {
  {     . v1 m$ L3 L  v7 M. A' U: O7 m" F
  alert("请输入注册名");     
" G6 R; o3 H1 [8 z+ O  o  document.sform1.id.focus();     7 f+ Z2 N* Z( U: ~
  return false;     
3 G" f  a7 G( n* ?; T# `% ?  }     6 f1 d  U' @% w0 R% X5 R
     
  O4 y& a( K7 {5 s/ J# b! N" x for (nIndex=0; nIndex<id.length; nIndex++)     ; \0 ]* ^$ h/ B  l' k( @; H
  {     
) e& |7 x7 ^# n6 m4 H8 E  w  cCheck = id.charAt(nIndex);     
( w7 x6 ?! f' j; d* L  E- g  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     - p0 w" f; L3 i8 ~2 ?2 ~
   {     
6 W- }$ ^' r+ ?$ B+ W; p   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ' X2 O" v+ Z5 Y  E
   document.sform1.id.focus();     & G$ x7 K' d+ O) d/ |+ K
   return false;     8 V. e7 n- q# [/ |* e0 t$ f# w
   }     8 a* k" U9 ^: ]+ m, \
  }
" o8 f7 O; q, b: [2 T; I  chineseid = document.sform1.chineseid.value;     
! m2 z3 S- Q# Z& n% \6 b& E8 t0 {( o if (chineseid == "")     
( i! l+ P0 z0 D4 Z% n3 p  {     5 j# n$ I1 ?3 e# O& e
  alert("请输入中文昵称");     
( p2 F8 H& t" C* }6 v  document.sform1.chineseid.focus();     
+ g) j& ?1 _2 [- f( N1 s! W  return false;     
7 p1 h1 L( P* U$ b* h' s  }   
8 E6 v; x: f7 J+ |5 x. T3 L password = document.sform1.password.value;     / F5 H( g9 b; l$ J9 H
if (password == "")     
9 L* |% d: \8 [$ Z9 S8 z  {     ) P% }4 s2 i% g+ {( T( k- e; j
  alert("请输入登陆密码");     
1 ^! ~9 X* b# P6 I. G  document.sform1.password.focus();     7 c1 i4 W! M; C: ]& H, \+ |" O6 v4 W
  return false;     8 m0 Z; g2 f1 h& U- C  v3 J
  }
) i8 U1 q* m* F1 r password1 = document.sform1.password1.value;     * e  j! X+ H3 e7 l+ W6 E
if (password>password1)     4 u& R& s5 k5 P, t; x
  {
0 Q; R2 i% j- R7 B6 K3 W     alert("重复密码与登陆密码不相同");     
1 v4 @8 F% O1 {; ^# i  document.sform1.password.focus(); + Z8 e9 j! r0 ?1 w
                                document.sform1.password1.focus();     + r! U( [% \% Q2 w) o- H  _
  return false;- t% U& }0 g8 q0 P
  }  ; D* M( Y- ]. j, \1 ~& `9 l% @
if (password<password1)     
$ u1 F: R5 v# t! A) P# X# y  {' b+ s7 J7 O6 E9 @  t
     alert("重复密码与登陆密码不相同");     
' t7 P8 J/ N6 ^5 r* G5 G% b: ]  document.sform1.password.focus();
' O& g! J4 N" y- b. U- f/ U, t) K$ S4 Q                                document.sform1.password1.focus();     
( Q" f4 Z3 a1 g- P& S* b  l  return false;0 j- H/ E! t" I) w3 Y8 g3 S/ Y
  }
! K( F6 ^( o2 {; v# z# p: U2 s if (document.sform1.email.value == "")     7 O7 P' t" ]& h4 P, I
  {     $ y& S: B: H) @* ]  W" c; q
  alert("请输入您的E-MAIL地址");     
( n, C6 M, A+ Y  document.sform1.email.focus();     & _" d8 k& i: w6 A8 j* I
  return false;     0 s+ e% T# Q. R0 h' p/ y
  }     - A4 `% Y: r" |) @' n' R
      - p  q; r& s( ^$ z
email=document.sform1.email.value;      
' Q+ F6 m! N/ F, X emailerr=0     % O0 b! \/ l( `
for (i=0; i<email.length; i++)     4 }+ R* ~  G6 J2 g
  {     8 p/ I% }, U" v. a$ O+ X; l0 `
  if ((email.charAt(i) == "@") & (email.length > 5))     6 G  h# j( s6 y: R
   {     
/ b  m8 p* C; I% q  m" _     emailerr=emailerr+1     $ g" A' x5 v- ]+ `& D' s
   }     
( r* w6 C: C2 J" J  }     
7 V( G! b% R9 q" T& W+ k if (emailerr != 1)     
/ P8 \, S$ a  Z  T2 n( E. ~  b% A9 J  {     
1 i* U) p  t* ~# x5 t  alert("请输入正确的E-MAIL地址");     
6 f+ `8 j4 K7 _* @5 l" H  document.sform1.email.focus();     
) ~5 V4 s+ y2 q  return false;     5 S6 N5 c) ^6 f" f7 F- D/ s5 Y
  }           
5 b5 z  g1 V( n: d( E, r' d  6 e" ^$ z3 l/ `$ V: A1 g2 q
if (document.sform1.checkask.value=="") 1 i3 X  z4 ?' ~  s
  {
6 ^. a# E+ T/ ]; x7 ]/ M# ~   alert("密码提示问题不能为空");     
, M3 L* o2 f) ]) q2 D1 v: M   document.sform1.checkask.focus();     
  @8 k4 J0 L& W' U$ a% ~   return false;  # r7 A, Q. g# o2 l
  }   F! n9 p9 r5 t6 S
if (document.sform1.checkans.value=="") ! `* r( V2 c! i+ e% c; l1 N2 V
  {
2 C  E" V6 ?' z( I$ X" m   alert("您的密码提示问题答案不能为空"); 0 G5 I) ^2 r  T: c
   document.sform1.checkans.focus();     
- J1 ^% q: R: s$ @# ~. p, s* @3 W   return false;  1 A3 E3 w  V& _3 L4 N& E% ~& V
  }$ e# I' ]+ d* Z2 @
return true;     & {* ^& F7 e( j* Y& c+ Z6 O6 I
     
& _  o  h% t7 X- C9 C} * L: P8 h% y1 R: f" D/ a6 q
</script>

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