返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
# ^- D( O  r' R2 d$ m+ E! ?5 M<script language="javascript">     & |# d( J6 m# g! Y& S3 G
function IsDigit(cCheck)     
" `1 c% H- G, q& ^1 o/ d. S {     
  R6 V3 S5 _, \% v, b/ o' A9 f9 Y return (('0'<=cCheck) && (cCheck<='9'));     . W8 J1 y' P3 U  Y- ?
}     
! c+ `. [7 F* f- \/ Y# I- |     ; h. G2 \3 j8 i% B
function IsAlpha(cCheck)     8 {' Y- j6 M, }2 I) ?9 O* Z
{     
) `7 J" Q+ d# {9 I3 u return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     8 p/ ?! V! P  ~& e* X/ ^
}              2 t  G' U" e1 v' E3 s- v5 c
      * w+ M. w1 v. d0 c! c! \
function IsaNull(cCheck)          " d2 U% T" s/ w( W$ K
{          5 ]/ x. ]4 v7 F
return(cCheck != " ")         
$ @* c& v- q$ c6 b( P* K }                              
# x- S1 Z+ s! _- Z; @4 x$ s7 S- a      
$ O* h# Y* W) x" k5 tfunction checkform()     3 v! s! |) G; |& V$ S' t9 g) d
{ ) S, h+ U5 b* k
  id = document.sform1.id.value;     ) D2 f& I) H; M' R
if (id == "")     ! K8 U$ A6 U5 [' `% C# _$ u1 m
  {     % r* p7 a, K* D6 z8 P, D, G
  alert("请输入注册名");     8 ]$ |# v  f) c/ R
  document.sform1.id.focus();     3 ]' i3 D! p0 B0 H  r& n' ~
  return false;     7 h5 n# x8 O3 i1 ^
  }     - s8 B9 L9 k' E9 `$ r# [
     7 c0 g; s+ Q: c1 R6 [
for (nIndex=0; nIndex<id.length; nIndex++)     & r( @4 ?0 M! U' s5 I) E: U
  {     
& ]/ F9 I2 ?0 C8 @# X# W2 ^  cCheck = id.charAt(nIndex);     ) l+ _) S- ]1 y: ~5 |& U3 \
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     / X* r4 o: b8 [; {4 V: \& Q
   {     3 ~7 z4 w) T# E+ Q8 L
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     7 [) }; `1 N9 U5 w8 H
   document.sform1.id.focus();     
  K' P# g/ z) ~; L0 h   return false;     
$ A/ q2 n" }, b" i# B/ |" C   }     $ K& ^5 b& g+ y8 M9 i& u
  }
- _; H5 R8 ~' |2 }+ b% G; k  chineseid = document.sform1.chineseid.value;     
5 w1 j6 \% L  s( u% Z& T8 v if (chineseid == "")     
* i9 A4 M+ Y. k6 j# J  {     
+ K4 U  w9 q$ m' h) P$ c# ~0 T  alert("请输入中文昵称");     4 y1 g! S" t4 H4 s3 v
  document.sform1.chineseid.focus();     7 U7 ]* f8 n9 A3 c* F
  return false;     . v* H) F: [3 b' H% S* e0 D
  }   
- d% s8 Q( K4 O( W( @! v- M password = document.sform1.password.value;     
6 l$ [& {8 i9 s* M if (password == "")     5 `' m1 ^+ L3 k
  {     
, |. H" w$ r' b+ _$ Z. H7 y: [! e  alert("请输入登陆密码");     
% g8 c& E9 O* C5 M1 F3 }( W  document.sform1.password.focus();       p( e: W+ Z$ h- ^3 R# ?+ q/ w
  return false;     7 F( z% W! B0 c$ W+ Q- ~
  }
9 W( k) B7 _# T4 c4 Y' J" z password1 = document.sform1.password1.value;     
6 p- @1 l7 R& E/ n2 I- p9 F if (password>password1)     1 C3 [& I+ N2 y4 h! Y
  {
  A; V( M! s: O# ?# H' V+ U     alert("重复密码与登陆密码不相同");     
1 R; S5 j5 U% @6 P" H- o( w  document.sform1.password.focus(); 5 T/ b' m3 O! M( M) i/ N
                                document.sform1.password1.focus();     . R0 x$ c0 M" {* A" ]9 {
  return false;+ z" g! d$ N2 e) W: O; u) Y
  }  
7 g5 |5 u5 V/ [3 A- Dif (password<password1)     0 V# C: c, E1 Y# [. s) m
  {; p- o3 ~1 i9 ]4 I8 c
     alert("重复密码与登陆密码不相同");     
$ X# _1 X7 H% d; e  g5 J  document.sform1.password.focus();
; }  x+ h5 v  K                                document.sform1.password1.focus();     
8 i7 C+ C, ?- i" R$ G* G  return false;
% l3 \  a$ l9 T  _* O  } + }  n7 A$ Z4 c7 H- J! M
if (document.sform1.email.value == "")     
) x' q7 o4 O7 a% y  {     4 [3 ?: X# e+ y% z- k! C
  alert("请输入您的E-MAIL地址");     
& n. C, C* P# M! L  a$ n  document.sform1.email.focus();     5 f; W$ K* P; h& `6 q
  return false;     & A" j1 V7 V. o
  }     7 m9 i% b. s5 s7 H* Z/ t/ ~" [7 Y# D
      2 ?4 B- M( v. g( X3 z! i
email=document.sform1.email.value;      ( d. Y- l% m6 _% D
emailerr=0     
* L) A4 M! Z  r0 u1 l  r9 `& ~+ m for (i=0; i<email.length; i++)     
% D% {! ]/ |' v0 [5 k, D5 T7 e  {     : c( t9 M9 _7 {" C- @
  if ((email.charAt(i) == "@") & (email.length > 5))     
( d5 g/ F; @; I  ]3 p   {     
# y1 e1 |& R0 Y     emailerr=emailerr+1     
* Z8 X% P# F+ r   }     
/ I8 c7 d2 n* L, v. b$ o5 v  }     $ R( y+ R  J) h, X3 n$ a
if (emailerr != 1)     
, h' \$ c) D- a* F9 u2 P  {     
/ [1 U& o7 y/ h  L0 v  alert("请输入正确的E-MAIL地址");     
9 I6 E/ e) v% F' ^0 K( ]  document.sform1.email.focus();     / q" G# O0 J( \- s: q% J# x
  return false;     
: E  |$ p+ {  |5 E3 k. a  }           8 X6 M( y* o% ]! M
  9 B5 o% p2 q$ M7 P2 g9 e- h& J- g
if (document.sform1.checkask.value=="") $ W* e" G7 m# x' ^- I* G
  {
8 p9 j8 W5 w9 v# v/ Y  u$ E   alert("密码提示问题不能为空");     
9 ]$ P7 [4 o& d6 J, _& c   document.sform1.checkask.focus();     
% i' p+ g, p+ x4 r6 z4 |   return false;  
$ z' Q5 m( Q6 C# U# F: w  }
( L: ~2 Q: ]* q) O% L if (document.sform1.checkans.value=="")
: z% S( t) z& ^6 ]$ N  w7 ?  { 0 F3 i  r' ]3 |4 r- j% ?. r" [' ^
   alert("您的密码提示问题答案不能为空"); " M' R5 z+ N- l9 N" J3 `
   document.sform1.checkans.focus();     ; n5 v* h5 V+ S3 \: A
   return false;  
7 a9 A2 v8 U! b! G' E  }* J5 e8 F9 O& X  \
return true;     
, b7 l) @. \6 i. V# l3 L$ c: @     * d% j: g" ?! d
}
" O# O1 Z  X3 L* m6 T</script>

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