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

一个注册表单验证的js

这个脚本对你可能有帮助:/ C3 r( H$ m1 g  Y# Y
<script language="javascript">     % K3 M  i4 p0 s+ V; ~' z
function IsDigit(cCheck)     3 S# V% T$ Q& w3 j4 ]) W
{     
/ p' n: Y; q3 d. z return (('0'<=cCheck) && (cCheck<='9'));     
9 U$ \, T9 l* Y% {0 F$ v% X }     % r/ o! W4 B* y; l  m4 |* _* K
     
) H* t9 `4 g( E/ n* e0 r; zfunction IsAlpha(cCheck)     2 v3 o  Y# v; m+ J
{     ( Q# P" J3 C, s# e: a
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
  t4 N$ O* w: o" b }              
  [3 x0 h$ \+ |0 ]      
% @: o& e& @. j4 b6 Hfunction IsaNull(cCheck)          # A+ g3 Q* a! V7 g' b7 O
{          3 c, v' ?& [+ p) s
return(cCheck != " ")         
/ c& Z; Z0 J7 @ }                               : a' i6 R# _) G( {
      
# l- `; u7 |$ y3 p" O- D  Bfunction checkform()     
1 _- X6 X1 d: I7 f2 Y{
) x4 D8 U) ~% o* H' O  id = document.sform1.id.value;     
# Y7 |3 _2 q: q6 V( Y3 K! N& Y0 U: }' A if (id == "")     $ ~9 n) q% E% G( c( V; n# F
  {     ) h% b9 H5 G+ G4 _* g: i3 z' r
  alert("请输入注册名");     
+ x8 x/ f( d: x3 T" J  document.sform1.id.focus();     
$ a/ A% U* b- n, s; P  return false;     / Z+ c' W6 Z3 d
  }     , h. _" P5 ]9 X' D
     % ]8 u/ `0 R6 O0 R
for (nIndex=0; nIndex<id.length; nIndex++)     
& I, W! o2 p  O2 p% h0 T. A  {     * _8 F7 x- ^, k( ~& V* d. m. K( N  k
  cCheck = id.charAt(nIndex);     
4 a/ g  V  q+ h! F2 V  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     8 C" u- O2 \  d( I* U! A
   {     
! ]  e4 a% V' K- j   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     3 D& A  V- Y# s# N/ T" }! p) B
   document.sform1.id.focus();     & W1 ?* X- p8 Y4 V5 y  O
   return false;     / G# T7 P- h2 P# r& B
   }     
1 F3 I3 x1 C+ W2 a" r  }
- z* `" ~8 h: |6 `& l) l; F  chineseid = document.sform1.chineseid.value;     8 g. X- y* h! V
if (chineseid == "")     
, [3 h$ C9 L0 x% ~" j  {     5 {$ k2 i7 l: H+ Y8 t5 I
  alert("请输入中文昵称");     
$ w4 ?/ z/ h/ x3 s  document.sform1.chineseid.focus();     
- D) E6 M, T. s$ L' X2 K8 r  return false;     
& Z' V' Y/ V/ c. t  }    + E) C5 o% u0 n6 V% F# g
password = document.sform1.password.value;     ! K" L/ u* R1 }$ A
if (password == "")     
) k2 r) Y  f2 T# {2 q4 U7 f  {     . t9 J% l2 B! ]) o+ m
  alert("请输入登陆密码");     0 D& b7 ?# J/ `9 ?- `, N
  document.sform1.password.focus();     + f0 R* s, Y* e5 e
  return false;     
+ b: N0 i) w7 t9 w  B  }
* X' e3 d2 s3 g1 G password1 = document.sform1.password1.value;     
. ~; D! d# a. B6 G2 l if (password>password1)     
# |6 i7 k! l; J' I% n- r  {4 R# l1 K8 R0 f$ `
     alert("重复密码与登陆密码不相同");     3 o0 V; O# S9 [) y! \3 P1 \
  document.sform1.password.focus();
+ |7 q+ C6 w4 t4 y, P/ v3 b$ N0 d                                document.sform1.password1.focus();     
+ ]! I& u$ f1 o! q6 w0 s' n  return false;5 p6 I* l; L) I. X
  }  
  A$ s) p1 @" p4 v/ B3 y# `if (password<password1)     7 ]; c% P: ]0 B$ {% e
  {' l& _$ `1 }  \
     alert("重复密码与登陆密码不相同");     5 i2 q  z/ k9 r
  document.sform1.password.focus(); 6 m3 r( J0 o  [5 g9 S& R, T4 Y8 Q. i
                                document.sform1.password1.focus();     1 r& N% q2 ]1 i' U; n
  return false;& h+ D$ K: n5 |" Z% Q4 V# I9 p6 f
  }
# s/ z8 n- H' r if (document.sform1.email.value == "")     " l  G" S6 U9 D8 t7 h# Q, O* l) u
  {     ! V  ?7 W# V6 u* O; Y
  alert("请输入您的E-MAIL地址");       r, j9 k4 V* `8 o
  document.sform1.email.focus();     
3 t9 {) V" O5 y  E( }* g2 {  return false;     $ }; ]  p6 Z$ e9 k  M
  }     1 @# n4 T. `8 A& I- X
      % P0 H( D+ n9 T* y
email=document.sform1.email.value;      
9 s' T9 G( r  h4 J$ [' D emailerr=0     3 O$ o" h. t% m" I# o+ ?) m  f
for (i=0; i<email.length; i++)     
5 O  D4 D8 g5 \- S% d9 Z6 x( v* W# |  {     + C; ^* [* g3 \! `9 Q+ ?4 u* w
  if ((email.charAt(i) == "@") & (email.length > 5))     
! E$ W, b8 k% s2 R* c4 o, [3 B   {     
# [8 u; a! ]( }# U     emailerr=emailerr+1     
6 p& k+ K1 {# `4 V( Z   }     " E2 p* e- N9 z, O. [3 g+ e, @
  }     
5 w- z0 \/ H) n  t if (emailerr != 1)     
1 t0 N# \9 S+ `) V* A  {     
  w8 x# z" J! D5 T) `  alert("请输入正确的E-MAIL地址");     7 G! m. M3 f1 f1 A' Q' s
  document.sform1.email.focus();     8 }+ }) M0 g  ^$ j- x; x) i8 C
  return false;     
- \1 Z, l% \" l4 @& r( Z  }           
9 P6 O* t# M' [+ @6 r3 ~3 @% N  
- v& u: `; d$ f; n4 a3 L! N if (document.sform1.checkask.value=="")
! a% T% Z2 ~& l" g2 N  { 1 b; E, S4 @! ^, b% l7 E. _
   alert("密码提示问题不能为空");     . m% j' V" [8 f- e. Q9 q9 e
   document.sform1.checkask.focus();     % ]0 c' N# E; _7 O& C+ ~4 o3 S6 }9 H
   return false;  + S8 v% P% C' V- y/ I- Y
  }
8 S* }  u  B" ?% i6 { if (document.sform1.checkans.value=="")
! p" Y& p- _: g  p  {
- p5 r6 T2 m, V   alert("您的密码提示问题答案不能为空"); 0 G1 [# j3 ?9 K9 r' d
   document.sform1.checkans.focus();     
% w+ Z) Q/ d/ ?- y# i7 ~3 ]3 v   return false;  ! b. _9 U% c/ j8 e7 |: m% _
  }
% I* s9 l; [; I return true;     
1 k; a0 C$ P. R7 G2 n  l  p7 a0 o     : w5 n0 v; I' p( J$ G$ _+ ]6 l/ b
}
- Z) G) b: y6 `</script>

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