返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:, P" Q+ A$ ]% V# M. Q0 f0 I) x
<script language="javascript">     * G" C1 z: [: F; ]* ]
function IsDigit(cCheck)     * ]+ D- A# s2 z" L) Q
{     2 Y4 @$ F  ~+ r4 H% U/ D, }
return (('0'<=cCheck) && (cCheck<='9'));     
+ B& W! q% {- ?+ W1 [1 r }     . _  G' {4 X3 N% q1 d9 x
     7 b/ N' Z# }. d
function IsAlpha(cCheck)     
" O3 E0 Q( a0 W3 ^3 |: ~" w/ ~ {     6 `$ Q& k+ u" h; n% a4 x1 P" P2 f
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     : P1 |( ?. N: i8 {
}              9 N+ {/ r0 ]: g
      3 R% A" T6 [! H: {0 ^7 k: `
function IsaNull(cCheck)          & c0 e" T  K6 K9 J, z8 E  p" ^
{          ) R+ Z9 N- F2 o% N
return(cCheck != " ")         0 w5 X/ u: k- Z+ }1 e! Y5 `
}                              
5 h& F: h8 h, [# q2 h9 }- v      
' U4 A3 q) ^: r( Afunction checkform()     4 [, R# f1 K# e. x: h
{ 3 ~' R3 n8 q8 X: Q
  id = document.sform1.id.value;     / y: a0 i. `& m* n
if (id == "")     . N1 E  s  D* S/ W7 {$ {
  {     & c- A9 t* I1 r1 H# a  Z
  alert("请输入注册名");     
% I! A$ B8 }& ?; W) Y  document.sform1.id.focus();     
" n: Z  I2 m' F, T  return false;     6 T+ |! ~6 D. J6 K4 E3 j% P9 s
  }     ( f* Z6 j5 D7 ^- B
     ' i7 x: o' f' J, W$ ]4 E
for (nIndex=0; nIndex<id.length; nIndex++)     2 o/ q6 [7 k: t: T) G" ]9 S
  {     
) _, s/ K+ J" I% D3 t  cCheck = id.charAt(nIndex);     
" M1 G/ K, _# k  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
9 z$ j! ~4 u+ V9 U/ c$ |   {     - e; t" x6 m/ M. l
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
$ H& m9 q, ~  _1 o/ }) o1 [: u' o   document.sform1.id.focus();     7 y$ y& X! Q5 |! D  L9 u2 ?+ y1 k
   return false;     
' ^  U9 i1 T  F% M' W7 [   }     
) W( k+ R  A- ~, C  }
% Y: y6 ~* Y, ]8 i  chineseid = document.sform1.chineseid.value;     
: l+ L+ ?8 s; m" h( p9 d' @) E' a% Q if (chineseid == "")     ( D/ ]  }3 ^1 U6 a% O
  {     
, Z$ K$ n; u6 T* O* s, M  alert("请输入中文昵称");     ; ~2 A2 @2 o& ^/ O1 B  a
  document.sform1.chineseid.focus();     
& @* ?& |$ j& }. |  return false;     % G% R( q/ F$ T) ]: K/ }
  }   
7 |7 B9 |& r5 G- a3 ?, S+ k3 b password = document.sform1.password.value;     * K7 D/ t  W( M" K( q' y
if (password == "")     ' ]6 @$ J- q9 J2 t/ c
  {     1 d8 k- F4 A9 S) y- t3 u  h
  alert("请输入登陆密码");     
  [5 X) m  Q- H3 n  }/ Y# z  document.sform1.password.focus();     / |/ j' E0 }+ z9 x/ x9 H, q
  return false;     2 K% Z7 h! z/ o: F5 ~" `& B
  } & u, T0 I8 G4 {2 N
password1 = document.sform1.password1.value;     
, N+ L: ?- \' ?5 L" d if (password>password1)     
- t8 F0 Y# ~, g* h% d6 l  {
# o8 L& [+ R+ G     alert("重复密码与登陆密码不相同");     2 c5 c/ D2 U: T0 c( |) b: Q6 s# {
  document.sform1.password.focus(); 8 W4 N, V. k% F$ {
                                document.sform1.password1.focus();     # u3 L4 G: a  C. c8 \) F* S
  return false;' M) q- P2 A  @( L& @0 v; I
  }  $ p0 Q6 W0 \$ t% H2 I5 ^1 m
if (password<password1)     ' {% k9 F! y/ E+ ^) K- j4 G
  {
# W2 D; e: I+ Y9 d     alert("重复密码与登陆密码不相同");     
5 v" Q* ?' [8 f6 c5 ?8 i  document.sform1.password.focus();
9 {  Z- [0 M* |1 m  v$ t                                document.sform1.password1.focus();     
, t; Y; X/ Q! F% ?4 I  return false;( M; _. m: r2 Y/ m
  }
+ X7 o* ^+ Q, G! y: x' E if (document.sform1.email.value == "")     
/ X( |4 z+ [# G& j  {     / ^1 U5 ^8 \2 s8 K- p
  alert("请输入您的E-MAIL地址");     
" z; @7 W, V) I3 k' f  document.sform1.email.focus();     6 Q: l, i& b" v( q- W7 U+ @( G0 _- y
  return false;     
. _0 p) F" Y/ I. s3 `  }     & R) \1 H# ^8 U6 Q
      9 A8 r; F7 |0 C) U! I, b
email=document.sform1.email.value;      
. ^8 F" Q& C0 Q" M" c) C# z emailerr=0     ) ?  O9 ~4 X% N8 ?
for (i=0; i<email.length; i++)     + a. g+ x) w/ `6 C
  {     
+ y2 H0 k$ ]# i# i) n) D  if ((email.charAt(i) == "@") & (email.length > 5))     
6 Z  \4 z/ h; \( s; u1 K   {     
- R- b# j8 F2 _& `2 r* B' t5 L& s     emailerr=emailerr+1     " a1 Y4 Y" a$ G0 s3 Q
   }     
; f$ x0 g1 j) W# m. w' ?2 p- l: B  }     " e6 K, c! h2 Z
if (emailerr != 1)     
$ D+ v, y1 b; S, h; E# E+ U  {     
& T; @4 g9 ~1 j& N  alert("请输入正确的E-MAIL地址");     
" J. f- R5 |- b" t& s$ Q# O) n" `0 N  document.sform1.email.focus();     $ ~# U1 ]: y) ]6 [! ]8 j# t2 H
  return false;     0 W( i/ A! }4 V$ W4 m! y% c
  }           
# f" W+ _! l  A3 O  + f; @/ |0 E0 ^
if (document.sform1.checkask.value=="")
; l$ e. N* O& |; ]: Q' d- y  {
7 q4 k& C% r- k- g6 S: s' E   alert("密码提示问题不能为空");     
- t+ Z  p9 V2 W   document.sform1.checkask.focus();     
2 D9 @4 ~8 r, j" c1 V% z3 P   return false;  5 s1 ^8 D! J2 M
  }
2 c4 t+ D/ j) d6 Z' E if (document.sform1.checkans.value=="")
) f" K# f8 E) `  {
- @* ?$ f# o& _0 P: g   alert("您的密码提示问题答案不能为空");
; F, H& T0 U5 }0 o   document.sform1.checkans.focus();     
) S& ]2 c; B$ U4 R; }1 Z   return false;  & b( S* _7 u- p
  }
5 v/ l4 q% B! T" f4 C0 G return true;     
2 E" A" M) f3 b! Q! E4 k: w     
* L$ K* v$ \0 a1 s( i# q) ]} # o+ X) N% a' @  F! u5 M8 ?; C
</script>

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