返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
) x5 ?; m, {1 j' t9 W0 ^<script language="javascript">     
. N! U) Y* @" u. }3 cfunction IsDigit(cCheck)     % D3 q) n& h: ^5 [! r1 k
{     + ~4 t7 n9 w, F) c; K+ D
return (('0'<=cCheck) && (cCheck<='9'));     
. J. c+ D3 N2 m3 e5 q: l" H }     
% }% a  X2 v+ h1 @. u8 `     : r% a& B3 }, Y8 q- n  D$ F& e
function IsAlpha(cCheck)     9 Q9 r  j* S2 F' i0 z' Q
{     
$ S( s# E4 o! ~ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     0 ^8 ]: P$ p( Z& s; b
}              
5 W5 K* N; j0 t7 h7 R0 x" v, ~; T      
* n; D+ f7 r8 s# N, ]# mfunction IsaNull(cCheck)         
& I+ }( m. R2 \6 `, v {         
6 U. G9 }6 N4 `9 q% O, | return(cCheck != " ")         
% J( Q+ Y% l" n, d2 h) n) N$ b }                               # v2 S. i3 g# X2 d0 U# q
      % R1 f3 L2 @6 F8 ~  H; w  s# T
function checkform()     
  Q" J9 C  \* L6 Y* {, w1 C{ ( [3 j$ E9 Q; W) D
  id = document.sform1.id.value;     
9 C0 ]) K- Q! ~ if (id == "")     5 y7 y$ i# ~- `% z
  {     2 A0 m# m% M5 E8 L
  alert("请输入注册名");     
* H9 U, R9 _+ |/ }: j$ D& M4 S, E  document.sform1.id.focus();     
, n& w1 R$ ^0 Y0 _. D  return false;     / a  F( l! E! D
  }     
7 y6 [% s- }; Q/ u+ l( C     " X  v' b" h2 a
for (nIndex=0; nIndex<id.length; nIndex++)     
% l1 U3 F" E: r6 n8 P& m# e  {     
+ O& ?* g  P* t9 ~4 H; E. q  cCheck = id.charAt(nIndex);     
8 I5 v; p, k( m8 l0 a, n  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
0 }6 L+ ?4 O7 X- f1 J8 Q, @3 k   {     / t8 Q2 X3 U( L* V
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ' r, @8 R% _- F) N
   document.sform1.id.focus();     
& k# k* j: B) {+ `; y3 V) W8 L   return false;     4 m: A* }3 U+ _  w7 v' |3 A3 Z3 Z$ A
   }     ( s( D, D' H. e9 ]9 x
  } 9 L9 y0 m( F" p2 C* P  u
  chineseid = document.sform1.chineseid.value;     $ _4 H! w% X, v, ]% W) [9 R
if (chineseid == "")     
7 P, E9 N" D. J1 U  {     9 |2 I& N( e; E4 }" m
  alert("请输入中文昵称");     
0 Z# X/ D6 x, v. G8 g  document.sform1.chineseid.focus();     . P0 c% \  M: S  b
  return false;     / o" i2 i, ?! }4 e
  }      O: \0 [9 y3 }- X5 k+ Y$ J  B$ J& O
password = document.sform1.password.value;     # w# X1 P. h! g  m, C$ R6 ?
if (password == "")     3 S2 u  K7 w- F, b: z# k3 l$ O
  {     
# g4 D2 f5 a  ]  r6 ^  alert("请输入登陆密码");     
1 d9 U5 B- L4 U' t% a7 t8 b  document.sform1.password.focus();     3 e" d1 u; z' U, J8 N, ^
  return false;     
+ ^) B4 b; q- W2 L, _/ Y& E) m# y' z  } . h9 f& H  x% ~  T% ]8 X
password1 = document.sform1.password1.value;     
% V$ s+ R. y; z3 @0 ]6 e/ b if (password>password1)     
4 ^6 h* G9 ?( r' v- k  {; Z. k+ S$ }% g) r7 k
     alert("重复密码与登陆密码不相同");     # |4 u6 S" M( ~' |
  document.sform1.password.focus();
% P$ R# e! o. A8 ^( Y+ s5 p                                document.sform1.password1.focus();     0 X* Q, a8 h$ F7 Z/ [4 I
  return false;( G4 s( C/ P9 p% f( h+ W
  }  
/ z" L2 r# F5 K$ Iif (password<password1)     
0 a. W; N+ s5 Z5 [, {  {/ @2 M/ G+ l, [( ~5 c
     alert("重复密码与登陆密码不相同");     $ ^. `' V* }2 r9 ^
  document.sform1.password.focus(); 1 j/ E% E5 Q9 L$ o/ R) Q
                                document.sform1.password1.focus();     ; `' F) v1 p4 P  U8 d% D
  return false;+ ~" @# ?+ ]" B! B! w; q  R
  } 9 `$ M  I# P( Y% l. t
if (document.sform1.email.value == "")     2 G/ B( V+ {* I4 `9 M  ~5 r
  {     
+ c5 l2 @+ P4 J; g4 L+ k1 y  alert("请输入您的E-MAIL地址");     
) h) {# s' A6 g! I  r: N0 [. R  document.sform1.email.focus();     , l+ M- z$ x4 X/ Q( z
  return false;     
9 `5 R1 }, W' U  }     0 X7 R+ p( o2 a% x0 ?+ V
      ! |# j# a/ f3 ]# ?: j1 h' @1 k7 F* T
email=document.sform1.email.value;      4 W  K" J. |. m8 A/ p
emailerr=0     
2 x7 @' m+ Z! S! d4 q, v2 \ for (i=0; i<email.length; i++)     
0 Q2 |! a+ ?# g6 h) j! [8 z  {     
, i, |# O; Y2 `  if ((email.charAt(i) == "@") & (email.length > 5))     
; i) L" o5 R% l8 {3 U   {     
4 p7 D2 H( r- X; `9 f3 e     emailerr=emailerr+1     
8 S8 l' ]* Y$ r& w, M' U- D   }     3 w4 {; W0 {0 F( w
  }     . `/ e' o5 x* G
if (emailerr != 1)     
1 O( ^. t2 F8 W7 U; e1 D6 C  {     ; i2 \8 u! `3 U0 Z# ^& K
  alert("请输入正确的E-MAIL地址");     ' Z9 `% O8 v# }4 q& P
  document.sform1.email.focus();     2 X4 d) R# o: Z
  return false;     ( O: R2 ?# `9 m4 j/ s
  }           * V5 |% ~* U6 M/ r# O3 B
  
( B5 E8 l9 ]  Z5 M* i* L' F if (document.sform1.checkask.value=="") 1 r3 J; }! M" J2 ~# x) X, m
  {
: q7 F- v! w/ B- a! j# z* p   alert("密码提示问题不能为空");     ) K6 l/ A$ Y, k/ H# a3 _& Y
   document.sform1.checkask.focus();     " P9 X7 q& E, u) D
   return false;  
8 y0 ?$ R7 |) g8 ?  }
+ Y8 J0 d& c7 Z9 z  k3 r! G if (document.sform1.checkans.value=="") - M% Y2 L% \# a2 T. P" l
  { 1 I5 _& o% [; K, z. _- D
   alert("您的密码提示问题答案不能为空");
) d2 h" z. K: v/ v( Z, y. `   document.sform1.checkans.focus();     
- I  O7 Q+ Z' m. k: o0 M) b   return false;  2 X7 i. S$ C  V
  }- ?% `+ Y- `+ g
return true;     
% N9 O! N, h; o& o     
/ _( V* d8 k: E& t' O- t( A}
! M7 F4 b% [! e& \% c</script>

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