返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
5 X5 ?# \; ~  ]<script language="javascript">     
* J2 S* g6 B9 i' s4 x  x$ ufunction IsDigit(cCheck)     2 f- C9 H8 u7 e5 z
{     & G" o2 }4 ^0 }+ Z7 y# S
return (('0'<=cCheck) && (cCheck<='9'));     
7 P0 t5 Q0 E: d0 F' G }     + A& H5 V4 I- {* U8 ^- O
     
9 Z/ |6 w/ y# q. J8 ~! lfunction IsAlpha(cCheck)     0 M7 V& S- G  N( c6 h2 }5 F% Y. i
{     " n/ X* L! I6 }9 ^! c
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
, u, i9 G" |" S4 [5 ~ }              % c2 `9 }- ^' W: v: m
      
7 d+ v' w# @4 xfunction IsaNull(cCheck)         
" o7 K3 R" A2 S% x( \  j {          " m" k  S7 |2 I( M7 E% h* Z
return(cCheck != " ")         8 K  ^& J. T( q" R" h0 p
}                               & {$ e: ?# @! Y. k  ]* z$ X
      1 P4 d! z4 w: I: r3 M
function checkform()     
4 _) e. M* ^; z* _" U: g& d6 o) k{
0 \' k) I" H9 i- l8 w  id = document.sform1.id.value;     ( O% g7 v% R/ ^
if (id == "")     
' C$ K- D. p0 Y  {     
# p: r) ~7 u) U! f5 S! c1 S  alert("请输入注册名");     
: [- g, P9 Q9 }; N( }  document.sform1.id.focus();     & q; v" x- q# ?% P! A4 u: y. ]
  return false;     7 h. @9 g) d; F5 D# `4 f- n7 \0 Z
  }     
2 y' K) _' N# C5 m; [# Y2 U& U     
3 p& ~9 g- v' Q/ b% S. K' z for (nIndex=0; nIndex<id.length; nIndex++)     
: C7 I. B" A( A; }% f6 a( c  {     6 s: t% H7 {8 G  L2 }3 ^$ K
  cCheck = id.charAt(nIndex);     ! K; b1 q+ [" }
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     & W, k) F/ F9 H5 C8 _+ R
   {     ' A; @# }- C7 H) n; R! f7 a
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
5 G& |4 f* c0 E   document.sform1.id.focus();     
% K; t0 M7 t( m) _   return false;     ' ^  Z6 Y- A1 n6 \1 P
   }     5 D& h* z5 G0 P* J( V4 A  G0 L/ x( V
  } 9 T- @2 a$ G) t* C' |, z
  chineseid = document.sform1.chineseid.value;     
7 }' s0 M2 R5 ?5 ? if (chineseid == "")       g) R. }( h+ Y" q. Y* \2 r& l
  {     , d6 C0 }) c: Q: @1 ^3 @4 {
  alert("请输入中文昵称");     
8 L- [5 D6 F0 V: s, X7 ?  document.sform1.chineseid.focus();     
/ t" w' h/ ]/ a3 Y5 Q  return false;     
$ z% f6 l4 h7 s# I, L  }    5 d  w+ ^- y0 ]$ U% M& V0 o
password = document.sform1.password.value;     
3 F, ^  K/ v% T2 D& } if (password == "")     
: O! e6 C) n. U: T, _  {     
7 v8 Q* P9 R) g; }- D" ^8 Q  alert("请输入登陆密码");     ) H3 G7 x0 k2 \! e- y# g3 Z
  document.sform1.password.focus();     
7 ]+ t! P6 h, {1 Z3 O) d& L- w  g4 C! b  return false;     ' p3 _1 g0 d' k& s+ x5 n
  }
! p' P! t7 Q& c4 G& C) |5 K password1 = document.sform1.password1.value;       v' e: I% K# k# B) }8 ~
if (password>password1)     / F# u) g4 ~" a
  {; |+ ]- @& A6 @/ X- k: a4 I( W  N; w' T6 A
     alert("重复密码与登陆密码不相同");     
& E6 N9 O7 Y- p/ h9 Z4 {2 W  document.sform1.password.focus();
$ @; k  K/ F; h7 `, C/ P9 ^                                document.sform1.password1.focus();     8 D; ?4 Z# I" M& N( E
  return false;
  I% o7 p. A4 L0 C  }  ; C' l! n# ?/ j+ y4 T( f+ B
if (password<password1)     
7 H$ w1 c. p2 r5 p$ t8 X, ]  {
5 M, |4 d+ M7 [. L9 j$ j     alert("重复密码与登陆密码不相同");       k9 C7 F" P) m7 Y
  document.sform1.password.focus(); + ?/ z1 S  z  E6 `( E3 r" ]
                                document.sform1.password1.focus();     
7 j6 x) H7 f% P- d+ b) a  return false;; \; {; O8 T9 J$ ?  [, }1 n
  } ; U" C# p0 b* w9 q
if (document.sform1.email.value == "")     " L1 t9 c9 G, g& S5 s3 ?
  {     3 g: R) y% h) K. j) O. ?5 R
  alert("请输入您的E-MAIL地址");     8 K# @; Q1 q1 t9 s. {' A$ G
  document.sform1.email.focus();     ; F. w7 ~; k# Y+ `
  return false;     ) `3 V- t: |8 L, ]% d+ C
  }     
% M; x! m2 e5 n3 d% j# f  O      " f, ?% g2 n! ?* u3 n
email=document.sform1.email.value;      # v( P4 T, e' u% ^" z
emailerr=0     
9 Q5 f& w: f8 f: { for (i=0; i<email.length; i++)     
6 A. h3 H# M( l  {     + Z& H8 D% i$ w( @0 {) f: w
  if ((email.charAt(i) == "@") & (email.length > 5))     
. u3 i* Z  b# ^; n9 V% v2 S3 F   {     & M9 T; J) q& A, u" T
     emailerr=emailerr+1     ; B, ~; G8 p/ _* l# z& O' D
   }     / D" D) Z7 C" h8 I5 r
  }     
; m% L: J5 A2 p if (emailerr != 1)     
' E4 v8 {) x6 h4 N4 |5 B; f  {     0 o2 _! z+ ~" U
  alert("请输入正确的E-MAIL地址");     7 D. A" d0 Q: V2 v
  document.sform1.email.focus();     
* G$ `* e  H; ?4 w  return false;     
$ l- }  C! s+ i* g; q) M  }           : Y8 f/ u' `& `3 d# ?+ s
  6 |& s# S3 k; ^
if (document.sform1.checkask.value=="") . h. \& {% Y& r- m9 D0 ?
  { + D  E. w6 R# F8 ?( ]) p: Q, u
   alert("密码提示问题不能为空");     
9 I( c" _' X9 |* U) d1 R( F   document.sform1.checkask.focus();     . P' v, j8 Z  s/ N4 P
   return false;  
/ D* m$ C) N+ z* w4 L  }
6 {$ y; ]  `  t7 I# E if (document.sform1.checkans.value=="")
3 `8 {2 ?  z" B3 O4 A, b' l8 x  { 2 E5 c. U, I  J. z8 L) v
   alert("您的密码提示问题答案不能为空"); 2 {. h+ Q% b. r! n  {) [3 w
   document.sform1.checkans.focus();     
6 N5 t3 D9 W) f$ B   return false;  # p  r; F' e. x9 R
  }
2 K5 u. j; o0 _; N2 s return true;     ' n2 Q1 X7 }: K
     
1 G+ ?& h/ @0 W+ Y% r}
  W, \: c% Q+ ^7 L1 y4 j</script>

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