返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:8 M0 F( ^/ n9 K9 U2 J( P
<script language="javascript">     
) C7 z; f/ v5 Q+ Dfunction IsDigit(cCheck)     
& M2 S8 o: i" K/ i, X6 F! ~ {     0 z1 R9 ?. W. T5 ^" `- W+ K
return (('0'<=cCheck) && (cCheck<='9'));     
* x$ ?' k: Y* W2 E% c- S: l$ Y2 ~# q }     
1 @( J- A) @# V: x" a9 E3 @     
/ g3 g' J. o: D! |" D4 d" {  ofunction IsAlpha(cCheck)     
' G: u. c  n: w {     $ W& b. [. x7 e& P) D+ I
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     9 T5 `8 X- l, t5 U; W2 u
}              
5 ~/ p# n; m- m/ A+ X/ Y" W1 |      + t+ ?0 f8 T7 _+ }
function IsaNull(cCheck)          5 J5 b1 O" Q. J( ^
{         
  `, \  m" f) I return(cCheck != " ")         ( l, H7 e1 }" C! L
}                               : R& Z1 p9 ]3 p" |7 ~" ^8 _
      
! H8 h  t0 E: Kfunction checkform()     5 s. F2 O* i1 |4 N
{ 8 i' j2 @8 w: L' l
  id = document.sform1.id.value;     
2 F$ u+ h$ Z2 _6 T/ \ if (id == "")     
: v" q5 Q" d9 d- _  {     
& ?' P" R# N9 [5 U& \1 @  alert("请输入注册名");     3 I& V7 w- F- h4 r3 \; i' S$ d0 V! A
  document.sform1.id.focus();     
4 k3 D! `6 T! Q0 P  r) }  return false;     
8 g0 ?9 {" M4 j+ z6 j' @  }     8 e% \# s) d4 T; T3 Y4 v
     9 V: Q! _" b4 }3 c( |
for (nIndex=0; nIndex<id.length; nIndex++)       s9 v) i1 Z/ X0 l$ A
  {       U/ |, q* ~8 e& s9 e- r
  cCheck = id.charAt(nIndex);     7 J# f) [# g7 z4 o- U+ ~0 j
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
# M) m  T, b5 |% |0 ]7 o) J   {     
6 \9 G; H  t6 S" X& ]. {6 U. @   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
. L/ G$ \: B- I' w- e2 Z* U9 d9 H7 }   document.sform1.id.focus();     
2 |0 w1 H7 S9 z5 X% d   return false;     ) i5 m# N9 U3 E4 l) u- }  Q1 U1 T
   }     
0 X- O/ O8 K( k" s% Q7 }3 A+ Y+ u  } 1 [! o) I/ R  W  U' i
  chineseid = document.sform1.chineseid.value;     . z8 {5 v$ q; S
if (chineseid == "")     ; f- P; r8 ]- x2 |! T6 H" O/ N5 |1 i
  {     
% F3 M# V8 v0 b4 K  q0 d& x$ _. b  alert("请输入中文昵称");     
+ f, X) n# z6 [$ n  document.sform1.chineseid.focus();     2 a' F! _8 ]' u6 S1 L; w1 @
  return false;     
$ h  y' u0 W) n- z4 @6 {+ a  }    ( N% y/ r8 v  [- s) s
password = document.sform1.password.value;     " F' @" }8 }) _" y2 a
if (password == "")     
, U5 t/ t: s2 s) S  {     ' R7 ~& b: @* w8 h9 T
  alert("请输入登陆密码");     
4 m9 y! u- M( ]) ~5 w5 g/ |6 r, X  document.sform1.password.focus();     ( {' N1 K/ V" A3 O9 v0 t
  return false;       A3 @* g7 _; G
  }
8 O# ?3 T- ]! M4 ? password1 = document.sform1.password1.value;     7 o% @+ N5 T" k2 M1 {+ U" d$ P
if (password>password1)     
; n( I* D6 h; ]8 ^4 V  {
  x  \! G5 A0 `/ k0 B9 B" f' m+ R$ E     alert("重复密码与登陆密码不相同");     
' T9 ]9 T. P: P- s, _" D4 k  document.sform1.password.focus(); 5 V- F) O* p& [: g! H' }
                                document.sform1.password1.focus();     
4 c* x' f6 Q" g* |% }  return false;
+ ]  D$ c8 {# I/ l7 m) A! q2 c" y0 K  }  7 D3 j+ R; z$ i8 Q
if (password<password1)     
" c3 w# A$ b. M# O  {' ?" V& Y4 k% h6 W% U3 u. l; f
     alert("重复密码与登陆密码不相同");     0 W5 ~2 l1 P" Y( B' Z8 U
  document.sform1.password.focus();   @! K( ?$ g8 P+ m. Q' J
                                document.sform1.password1.focus();     
0 [  a- Q+ r: N4 D) l4 Y  return false;, O1 w4 Z. [! }
  } 4 B4 m/ n& [! y2 o; V# K* @* y1 ~
if (document.sform1.email.value == "")     
( F3 d$ Y4 i3 z" a8 S: S$ O  {     
0 M/ P0 i' ]" D, |. t  alert("请输入您的E-MAIL地址");     9 p# E7 ~2 K4 y. W
  document.sform1.email.focus();     7 ^+ C" b- }' v6 i# t
  return false;     
) t$ o/ A7 Q* ?! l( r4 a  }     / L5 g; m- E4 O
      
0 G+ P$ x/ A( }8 }8 T6 y email=document.sform1.email.value;      
, G* J3 t- m# { emailerr=0     ; N' }) M/ m3 W. R( {/ _
for (i=0; i<email.length; i++)     
0 I* y9 _8 {# R6 |  {     1 M8 s# G4 j& n) b. j! @
  if ((email.charAt(i) == "@") & (email.length > 5))     " o  R4 Q+ }5 z* v8 Y7 }
   {     
; _' ?4 x% H, N* I9 v8 U( P     emailerr=emailerr+1     ( F2 G% X) T  R' f- o9 f: {
   }     
+ f' {( s# l7 b' d- _3 c$ [  }     * U6 h4 N8 s1 K% @  [
if (emailerr != 1)     / y" x2 I  k! Z" x# s) D
  {     % a1 A1 Y% e. H5 A4 t
  alert("请输入正确的E-MAIL地址");     
( F$ @! }7 d1 U* K" e6 l' d7 t  \' P  document.sform1.email.focus();     
& @& G; e4 Z/ Y/ S  return false;     " ?3 _- x! n( L: R# A
  }           . T+ U( R6 f) E4 ~- N
  5 |3 z' ~9 A  Z" ~3 f; i# ]3 Q3 h
if (document.sform1.checkask.value=="")
, K2 l8 n- [: U8 j  {
* u* _. r( m' j   alert("密码提示问题不能为空");     ' M* i' U% M2 p; o- @1 |" |
   document.sform1.checkask.focus();     
# u( x# x- ~' O8 F( u   return false;  
8 p' l' b3 l) `% K1 `  }
( _, U6 X: X: s9 n if (document.sform1.checkans.value=="")
  ]2 _: t& a, T: a% M  { $ q- c- f! I1 y( h
   alert("您的密码提示问题答案不能为空");
; P1 F4 T9 w8 b7 {   document.sform1.checkans.focus();     
3 s6 `! D, Q& q- }) s   return false;  
* w6 ^) ~% S7 i  L' ]  }
2 I: }0 x# l* a% \6 K1 I return true;     
5 Y# a6 p8 D. f     
0 g; b2 D2 t& k5 M6 i}
1 y5 f4 e" t; H% |; z: `. u. N( f</script>

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