返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:& b+ M& h! N) P$ |9 \+ k
<script language="javascript">     
' `6 r1 ^: V+ J5 x; N; B8 Tfunction IsDigit(cCheck)     
1 p, J1 G/ ]. U' z; b {     
% H7 \" m) Y1 l return (('0'<=cCheck) && (cCheck<='9'));     2 A" f$ h% S" x! P2 K* G- _
}     
0 [! k5 A& x4 ~! ?3 i" s- o     , m* C/ F+ K! ]# ~, e% `- i
function IsAlpha(cCheck)     % T$ E. C2 S, c: j5 N8 B8 Z1 E# e
{     $ p# m4 l0 \, A! s! ]$ I0 k& S
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     . k* r* x1 V3 L6 F
}              
) p$ z  X. {# |1 c      + [( a. x' d: t* v( U
function IsaNull(cCheck)          - p- s! a% h$ \, X
{          6 V7 o4 `! G6 k* E. T6 B
return(cCheck != " ")         
; ^. H; D# n1 g* g }                               / @  e  i0 ?2 M
      9 O9 C! _# O8 l
function checkform()     : X$ _1 E3 ?9 v0 M! B1 G
{
0 j7 \3 n5 Z* m7 R  id = document.sform1.id.value;     
, T8 S; {( F* V1 [: O( u% K% n if (id == "")     
7 S/ l7 g6 {& O; p3 u4 N9 R* m  {     $ o' P8 e" H" [
  alert("请输入注册名");     
% x8 ~) `" d* h( ?3 a5 u  document.sform1.id.focus();     3 [1 E( z( D% R
  return false;     9 I/ M# d( R4 K2 c5 o& l+ L- G7 a
  }     
9 k" m, h# p6 i. I2 J$ t     5 I& _1 `  _1 K8 W  f" W4 i$ a
for (nIndex=0; nIndex<id.length; nIndex++)     
6 K8 d3 d5 r" U) i% E- L) h  {     
. `& H( C* k; s0 y7 l4 z0 L+ G  cCheck = id.charAt(nIndex);     ' x# t/ ?( V- Z- c, t3 J  R9 b* l
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     & S7 Y7 [$ i) {' J% W1 k
   {     
; v! S& N& K4 O; u1 d  V   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
7 _, r4 |9 |* `# r( X   document.sform1.id.focus();     
0 N0 b" q% c9 O   return false;     " {% G- h( `; |$ u$ ?/ v  m' b
   }     & u( O/ N5 I/ y% i
  } / n* u% R8 x3 p2 R
  chineseid = document.sform1.chineseid.value;     $ Z. m4 \; w7 H) Z& Y, q
if (chineseid == "")     
/ x7 m+ c! l& B1 h  V0 S  {     8 ]6 Z7 Z1 E$ s/ S) D2 U5 E* }
  alert("请输入中文昵称");     
3 g( M. y6 Z4 d, k2 p  document.sform1.chineseid.focus();     5 V; e& D: J& `0 R" s
  return false;     
- ~- f5 K' I3 U6 a8 H  }   
+ P! I. P) O5 X password = document.sform1.password.value;     1 N7 [: l: W* ]
if (password == "")     
1 ^' I8 Z( s! C( B  {     . `/ E1 W1 @) P) T
  alert("请输入登陆密码");     5 w, Z( }. H. ~. V' q7 C* y
  document.sform1.password.focus();     1 j& k7 U& e; O  H" H6 {; G5 X; \0 T$ O
  return false;     + U7 c& I8 Y/ E1 _
  }
* S- O) a" c& K7 k password1 = document.sform1.password1.value;     
, v, l- m7 o3 o5 J0 Y if (password>password1)     / i" ?; t: J2 ^% k) C0 r# ?
  {6 I+ n2 y; J* I. ^
     alert("重复密码与登陆密码不相同");     
! K! `5 b/ e% S* P3 E  document.sform1.password.focus(); 6 I$ T! i' H8 W! ^2 Q. l
                                document.sform1.password1.focus();     7 q6 a0 x& z) L9 K  L4 i$ q9 c
  return false;9 V3 {, S( \$ z; I+ |# b: i- i
  }  
0 c) ~! ~; |. Nif (password<password1)     
" _/ q" \6 g4 z5 K( I  {+ U; ^# M+ R, e+ C4 i
     alert("重复密码与登陆密码不相同");     ! H' i/ d& M9 Z6 X
  document.sform1.password.focus(); + x) C' i1 P* N9 y( x/ W
                                document.sform1.password1.focus();     8 J! X& ?. g3 J7 ]: K
  return false;
% u# \* G7 E0 t  }
2 s) G! x/ K5 G' ~$ b' b0 t4 J if (document.sform1.email.value == "")     
# @. T- \# m5 i  j( a! j  L+ f  {     
3 B6 f0 s  F9 I4 Y* I  alert("请输入您的E-MAIL地址");       R, R) G" x8 w. x
  document.sform1.email.focus();     
) Q6 x( O6 @( `  return false;     / y/ `1 K: X0 x
  }     - F& i- ~  s! t( L& H
      
. B9 W+ T2 k- W( w2 t+ K email=document.sform1.email.value;      
2 D& k( f% ^3 w( ^ emailerr=0     
/ D2 }# @' r) u$ a0 j for (i=0; i<email.length; i++)     2 x, v6 h: D7 s: e  n
  {     9 N! z" x  L( U; p) e0 u* U
  if ((email.charAt(i) == "@") & (email.length > 5))     " Q/ a/ H$ G$ |. d
   {     / _1 P3 x9 O/ q2 [4 @; c* O, J
     emailerr=emailerr+1     
! g" U) B7 Y* I1 U! [; C8 S   }     . m# d* `* }( [% J
  }     
: f: @" d2 F- p! N: D4 K if (emailerr != 1)     7 `2 Z: S! z, k1 h! e" t7 {( U* u( X
  {     
% |1 O0 V8 {" \" P& ]  alert("请输入正确的E-MAIL地址");     
* c  l: V% u  O! R  document.sform1.email.focus();     # i7 M6 s+ h) h. }7 n1 E
  return false;     
1 A0 A: y, S5 k: ]( |4 G% v  }           * Y/ i" I' V8 O! Z* K( _! [- g
  3 h$ i. G" B& N$ u4 v4 J$ L
if (document.sform1.checkask.value=="") ' W3 o! O0 s* S# r; s' R4 g
  {
, ^# D; @8 o: P6 R; h# J   alert("密码提示问题不能为空");     
6 E1 |5 n5 m5 U   document.sform1.checkask.focus();     # Z  E/ O9 @1 T5 y" Z! l# g  N7 s" \7 C
   return false;  
5 a$ g/ W' _$ p; M3 P8 f" A3 `/ x) `( Q3 E  } 7 Y0 X- ?1 x  n% C$ l! L
if (document.sform1.checkans.value=="")
; i  t$ x0 `9 W  c& a1 G$ ^/ c. R  { 8 ~9 H2 e' L2 l# b4 N0 e0 y
   alert("您的密码提示问题答案不能为空"); / Q% e' j" o$ r0 r/ X. U+ D( n
   document.sform1.checkans.focus();     # K/ a; ?/ W& v7 G' o+ l& j7 S# k
   return false;  
. W- m% Z( e. g; M5 I3 y6 `; o  }
: S3 F+ o$ ?/ e9 G# f0 `: u& g return true;     / {( Z% U) M' _
     4 m; z' g& l5 z. x; j. F
} % q8 x: t+ q, Z* A
</script>

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