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

一个注册表单验证的js

这个脚本对你可能有帮助:; K# F1 T% @9 |' N: I% u+ @; A
<script language="javascript">     
; j, ]* z4 o; G2 N6 S, O  s& X7 U7 Kfunction IsDigit(cCheck)     , p- [: M1 q* E6 @2 ]
{     / X3 x5 _% T4 N# A
return (('0'<=cCheck) && (cCheck<='9'));     4 G) G" E3 A/ v5 D+ o
}     
- w# @. S! ^, t$ w$ L  ]     ; d4 m# A  {8 B7 ~4 L/ w! G
function IsAlpha(cCheck)     
7 a8 M$ T. |% g- W/ k {     
) c- j0 y6 k5 _" I/ e: W% o* X$ m return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
: l5 E1 V7 y$ f  i7 m% l }              
# ^3 {% f/ j* `+ j% ^      9 m2 W! I6 K: o( H! ~3 c* ]/ w$ y
function IsaNull(cCheck)          ( D$ q8 v* l& ?: y
{         
2 T0 Z6 u! A9 c return(cCheck != " ")         
+ t, e2 e  R6 k+ p4 j }                              
$ B3 d! y. ~' R7 b, {7 X/ c      
9 E$ T3 G3 r& I% v5 F) M, Ffunction checkform()     
! X: x+ u' O% u3 M& T{
. Z  c4 m( _" R: {; Q  id = document.sform1.id.value;     ( U- v% H8 m+ V) v! E7 O+ V
if (id == "")     ! F( H( f" n/ Z8 L: V7 k
  {     
6 X* a$ C, [! ~' m# [# R( _' ~  alert("请输入注册名");     + _9 k( S, H% s. P# W" n& Q
  document.sform1.id.focus();     & y* r7 `# w: R
  return false;     3 z5 t# ?. A/ s2 F. b
  }     
7 z; o: r. m" t- I- X1 j" v     & t8 D) n4 S% k+ H6 {0 Z  h
for (nIndex=0; nIndex<id.length; nIndex++)     " m6 x7 V/ j4 m+ i+ V: w8 J
  {     
$ S9 v4 J1 Z% e  cCheck = id.charAt(nIndex);     2 j" m( ^; t7 K1 I. e
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
# ]7 e3 i. {+ k6 W! H: ^   {     & k: c' }' P. K$ @0 i) N) `
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     4 b3 f( K0 p/ q: z
   document.sform1.id.focus();     0 P  A% }7 |( g& i3 k
   return false;     
$ \' W- u) s, y% L5 T  O/ W   }     1 b' A" d4 R% e, p, m
  }
+ |+ ]) F7 G, \- [7 d4 Z  chineseid = document.sform1.chineseid.value;     
+ y  n  Z# V+ ? if (chineseid == "")     
. }: e" A* A8 n- q6 z  {     
- q8 J2 W6 O. U+ W: R" f  alert("请输入中文昵称");     
( _! c1 ]) D! _  document.sform1.chineseid.focus();     ; e) M7 }' z. C
  return false;     ) R1 E5 q7 r2 `8 K! f: z
  }    8 \0 p8 h" U$ R% c" k7 S
password = document.sform1.password.value;     + S; M! }+ O. G0 K" J4 e" p
if (password == "")     . h+ a$ Z1 b1 f$ {
  {     - d. D$ \3 {# Q* W. n0 y/ ^
  alert("请输入登陆密码");     
1 r4 y) N" b5 G+ V) G9 M/ h% B  document.sform1.password.focus();     
7 ~+ e; S1 i( z1 u  return false;     
; m: x# B; c+ M  }
9 T6 h) g- Q* Q1 P3 X# x password1 = document.sform1.password1.value;     
0 t( N% b6 q/ A6 x+ c: [ if (password>password1)     
4 P& Y6 J9 |* m! N  {" z" v( N$ E, k
     alert("重复密码与登陆密码不相同");     
) i" r9 V0 x6 a* L, o  document.sform1.password.focus();
9 a8 ?# r/ D* q! R2 u3 N                                document.sform1.password1.focus();     
# B" n$ N8 V1 C5 [' l" s$ X! \  return false;! J; v$ u2 I/ y6 u
  }  ; D0 n! w: E# `# G9 |
if (password<password1)     ( d! U8 ], J5 B1 a; l
  {" H8 D% f; v) M/ _
     alert("重复密码与登陆密码不相同");     . m. o& \! }* z2 h2 h
  document.sform1.password.focus(); ' r1 G' K- J3 U9 g6 `) o3 Y
                                document.sform1.password1.focus();     
/ n8 J/ A& _# o6 L% ]/ O5 i6 q  return false;
0 D8 N' A; H% @4 V7 I0 p( N, m. q+ X2 q  } ! \3 V" U: x, y/ y
if (document.sform1.email.value == "")     
$ `% R; V3 F% \! T$ Q; l  {     
7 z# v& g+ s3 U) V) ?: @# F  alert("请输入您的E-MAIL地址");     ( ^, L' a2 |- l. }, F" N
  document.sform1.email.focus();     
7 `. v( U1 d- J2 j$ L; g  return false;     
" [( i5 E  S0 C  \9 k- V# I  }       U1 }+ H, K+ }- _- S% ]' |0 `9 E
      
* _  y: R: a! {; \: ?# P2 M0 F email=document.sform1.email.value;      4 O2 t- b5 h% ]$ q- n
emailerr=0     
9 l& j6 P* G- m* U* O( ^9 y( k for (i=0; i<email.length; i++)     
1 L8 s. z0 g9 f* R* O3 I0 s$ b  {     
% F. s7 H5 k, T! F$ m: ]- S8 }  if ((email.charAt(i) == "@") & (email.length > 5))     6 q4 {7 S; b3 g0 O9 ?. e* Y) t
   {     
, c$ H' Z  I5 B5 k) D+ I     emailerr=emailerr+1     
9 C8 j+ ^5 [% y/ l' k   }     
- t- h9 D# q; l  }     
* y7 f6 Z; F: a: r4 r8 u6 _( A if (emailerr != 1)     1 n, l3 h8 i. B/ \' }
  {     $ W$ p! M3 y0 [# l: U4 K1 R7 F4 g
  alert("请输入正确的E-MAIL地址");     
. Y# J1 z5 J1 f# O# o  document.sform1.email.focus();     
4 |7 [7 f( z! i. E  s4 q  return false;     
9 e8 J' L% D, ^' u  }           , Z7 E% _0 `( {6 {1 g4 u
  
/ e# n& T8 m0 }3 ~9 S; I9 C  Z# d if (document.sform1.checkask.value=="") 8 R8 l8 b3 H2 K; @9 S
  { 9 d$ ?3 u, N2 z( V2 r9 q& p1 J. S
   alert("密码提示问题不能为空");     
& D6 b( N. M) @3 Y7 Q. {0 e! H/ S/ \   document.sform1.checkask.focus();     
5 z* s' R, r: d8 p! r$ Q   return false;  1 S. i$ X2 J# W
  } : s  ]3 U* Y+ g, D* @7 j
if (document.sform1.checkans.value=="") " O" {% S5 u3 n1 L
  {
8 y+ u* p8 H( c6 H6 Y% P2 |8 c. |   alert("您的密码提示问题答案不能为空"); 7 r: s8 C' `/ O
   document.sform1.checkans.focus();     * Q( h: K0 t/ i. {* N& C8 b
   return false;  9 Y1 w6 y$ n8 L( p
  }7 i3 Z; M" P& @
return true;     ' G0 Z  }+ B5 w+ J2 y
     
& \7 i5 h- M2 H3 \" E}
! Y! k; m0 F/ e</script>

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