获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:; {( [' f4 U6 o
<script language="javascript">     
" E% I4 U- m( k4 X3 Efunction IsDigit(cCheck)     + v4 M* i2 c' G5 K
{     6 i1 q5 Z# P5 K. h1 j0 k  Y; n
return (('0'<=cCheck) && (cCheck<='9'));     
8 z9 n5 V0 X; N5 T" T: b }     
; ~" P3 @, f. r2 Q  h. h4 Q) Q     
7 K! D0 p# o2 E2 V: K( [function IsAlpha(cCheck)     
! ?) z5 G  F- x+ U( H7 n {     
7 o+ ~1 B& f+ R. u return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     5 ?7 |. p' v7 ~  z6 f
}              $ V4 f$ e' S" I6 b& R, U: X
      
. o/ s% i% \5 ffunction IsaNull(cCheck)         
2 G  Q4 f9 H* P1 c- o/ ]7 Y; A {         
, l+ o/ c* a2 M8 O. ` return(cCheck != " ")         
2 U# A, G4 E, w- ?# Z7 R7 I }                                 Q8 i3 W+ s6 [& U$ W" U
      
/ c$ B/ L$ }( A$ Gfunction checkform()     1 d' C2 s1 x5 V; m. a. b
{ ; q' |% Y' p6 K/ e- @* ~
  id = document.sform1.id.value;     * b% G) c' J2 i# A( y, }% s
if (id == "")     
) t. ]5 s6 r- c# @4 k( Y  {     
8 @* b) @( R+ B% A. a2 v5 ]  alert("请输入注册名");     
0 w& B2 x4 V4 y8 \& v  document.sform1.id.focus();     
$ z0 D8 Q; R; G" _, n3 p4 \1 Y  return false;     
  {: ]) F! z* L! P" f  }     6 {9 P- Y9 T& Z5 H  e0 c3 C! j
     ' {" k0 N4 |. d% I6 s
for (nIndex=0; nIndex<id.length; nIndex++)     
! p7 Q0 B- {; b: ]  {     " v4 O* Y4 e- g
  cCheck = id.charAt(nIndex);     7 V# ~: n1 U$ M/ P  |4 b- v* G
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
7 R$ o" z3 ?/ X1 p  O( [   {     * y8 @% O  e* `# n& y% \
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     & w! _! a- d7 n( B/ c
   document.sform1.id.focus();     . i$ f" x( C, d: _8 k
   return false;     1 u* h, L2 A9 k% ]. i! N, U6 w
   }     
, K+ ?' K3 ?: V7 I: s' ^! x  } $ n$ Y: b% x8 T
  chineseid = document.sform1.chineseid.value;     
5 e2 j9 h8 g( Y! o if (chineseid == "")     5 p% j$ w  K4 K( y. U
  {     9 u! R, ^4 w& ^" c7 f( N& V
  alert("请输入中文昵称");     
; L3 i; q' j. b% e9 i, C; R' Q  document.sform1.chineseid.focus();     
" w  j  k+ t6 d2 l& J3 k( L8 s  return false;     
1 w% D' m3 @4 R  }    3 z0 a6 M* l. s" @
password = document.sform1.password.value;     5 R# U( U- _% A$ F" @/ b
if (password == "")     . _9 W( y5 V3 N. s3 L2 O  k& L6 e' Z
  {     5 \( S6 i! S( _, j
  alert("请输入登陆密码");     , ?& t: M0 R: v9 L% P/ P! g
  document.sform1.password.focus();     
7 R; U: J' e# u$ `0 \6 Z  return false;     
* \) b' X7 D+ ]5 M4 E4 ?9 W/ Z  }
, h8 X% F5 v- ]8 e/ K password1 = document.sform1.password1.value;     
' U, f: E5 \3 V1 i& [: k& x$ I if (password>password1)     , K: @/ y+ a" I
  {* Y- _: g( c- s, g* r, H3 j
     alert("重复密码与登陆密码不相同");     ; ~9 r: b3 K) v. K; _0 }+ I' L
  document.sform1.password.focus();
8 f8 {6 W+ P4 {0 `                                document.sform1.password1.focus();     
8 Z3 h8 f+ C, N* J6 q2 U6 T; g  return false;
; k9 \2 C! q$ m% N+ J- r7 A  }  ( ~" o$ y( G3 E! s
if (password<password1)     , o. W4 f5 r6 U5 `3 x& t8 G# B
  {
  j% c; s& a$ D# f! x     alert("重复密码与登陆密码不相同");     
6 _! \4 {6 f5 W, Y& n. p8 Q  document.sform1.password.focus();
% F& {# C) M" u5 w                                document.sform1.password1.focus();     
1 \& H# X: F$ k$ s9 d0 r! c4 Z, H  return false;
, [2 i9 B9 O( u- m, F  } ) W5 y5 l* W, g) @8 f) q
if (document.sform1.email.value == "")     ) q% l' Z+ v; H$ \' l! b' ^% U
  {     
: ~4 j* M8 S" O& U$ \! O  alert("请输入您的E-MAIL地址");     
1 @' G- N3 M* }) V* R2 U  document.sform1.email.focus();     
( [; J6 k: Z# ^1 g( C  return false;     . a# m2 q& U' @/ {* }
  }     
# z! {! B" n# k/ i/ R$ P* o4 a        K- w6 L6 P! u8 A0 G( [. T% C
email=document.sform1.email.value;      
# \. X" q1 l9 h/ V  v# Y emailerr=0     
  W' x! [' ?" B! ?5 v$ S% z for (i=0; i<email.length; i++)     " e8 c  \0 R$ F8 r. `
  {     
7 {9 }9 C- t" w( _: k6 y  if ((email.charAt(i) == "@") & (email.length > 5))     % o$ q9 \; R. n  r7 v' I) u
   {     / K* {% k; p8 c5 B
     emailerr=emailerr+1     1 `8 t6 _8 h! W% N
   }     
3 y$ O5 S. u" H  }     3 t% E( x7 G/ S4 i0 ^% T
if (emailerr != 1)     5 e% |. \# r4 M5 |9 A+ n+ s2 p
  {     1 q, E2 _( T. N
  alert("请输入正确的E-MAIL地址");     / h7 q% E* j2 Z
  document.sform1.email.focus();     
) d8 ^" [% B* b4 x; o4 h  return false;     2 _; z) M. g2 D" ?6 Q* {
  }           : f2 n- @+ g* J9 x' t; |
  : H6 ^8 @' z7 u8 P- v6 |
if (document.sform1.checkask.value=="")
9 A1 z: j+ m3 }0 u; r! ~5 @- u  { % M! c3 o9 r: s  m. |! F( Y
   alert("密码提示问题不能为空");     
! S& L$ }4 u# D& N% w# i. ?" o1 A6 {   document.sform1.checkask.focus();     # r" m$ S6 Y* S& ^$ s* w( H* M
   return false;  # c, u! G; W" I% M/ t
  }
5 L0 E% Y. Z! b0 Y' Z& m  d if (document.sform1.checkans.value=="") : {! L: E2 m1 }" B8 Y
  {
! A. g" Q  v9 M0 C& t   alert("您的密码提示问题答案不能为空"); $ h( U- s6 V  O. {
   document.sform1.checkans.focus();     
3 I2 P: h6 E# V8 u   return false;  ) P4 q& ^7 |, x6 j# F# N6 I
  }
; j4 ]0 R0 S) d+ I/ b return true;     
0 X8 s( P' v, i2 X     
% o( }; a( A+ u* Y3 q8 M} ( ^  \* n9 g0 p7 [. R" h1 o3 y
</script>

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