返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:& J& B. p* D2 i+ c- W# g& o
<script language="javascript">     ; W5 T+ n, H7 L6 q& l. i
function IsDigit(cCheck)     9 g: M1 X5 U' i
{     " f0 ?' }4 `. ^# A) ~
return (('0'<=cCheck) && (cCheck<='9'));     / d/ `& B+ T, G. B
}     
5 j- O: e' c, k* @+ G& U1 ^7 P  N/ ?     5 ^; G' v/ P5 x! {: @$ E3 T
function IsAlpha(cCheck)     " b( n# x: ~8 [& u0 c3 b0 Z( h
{     8 J6 A# `4 W+ P# w1 v+ f+ F" S  E
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
3 t7 X  }( `" V- Y }              7 R  E0 e8 i8 X: h
      
& s7 |$ I$ Q8 i! S8 u; Ofunction IsaNull(cCheck)          . n/ U6 V3 @4 E* [* s+ y0 g: U
{          5 I: S. Y: E% v- C
return(cCheck != " ")         
2 F4 [! t4 K, I8 \, T7 S( s }                               3 e6 D# J- Z: @: ]
      
$ t/ e" Q  X( s8 y, g3 a* G3 E& Mfunction checkform()     0 ^# \$ n. H  a7 x  o
{
, x/ L" R0 Y1 w" @1 W# N  id = document.sform1.id.value;     3 ~. h' \% r2 `6 R. v* r
if (id == "")     7 |( t% b: E8 \) l  u6 E1 s
  {     
' |- Z; q3 D2 w" N% c  alert("请输入注册名");     
1 Y- [  i- V$ d8 f6 S! K3 P2 m  document.sform1.id.focus();     + K% R7 b8 U+ O' ]/ ~6 V% z
  return false;     
8 h5 V' f7 s# E( y' Y  }     4 K" o( T* [# ?( D+ @
     & _  f5 \( F6 K. d9 t' w
for (nIndex=0; nIndex<id.length; nIndex++)     
( G. v: f6 {% j  {     
4 ^/ O9 N9 l% x# H5 Y$ x  cCheck = id.charAt(nIndex);     ) a+ h# N1 D% O) A6 d# Q1 I
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
; b! R. c. j9 d, ~' T; C5 G. g   {     
  \/ f3 w+ _, `; H3 p( m   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
2 o8 ~6 L6 z  J+ X   document.sform1.id.focus();     
6 F  W0 `; n. T( _" E0 w/ ^   return false;     
2 e- [9 G9 w2 Q4 _  G' g   }     
$ X4 ?6 P. h  ^( H2 r  }
5 G  L7 m3 h9 i" t$ b  chineseid = document.sform1.chineseid.value;     . s: S, }7 ~$ g8 H2 R3 Y6 A2 A
if (chineseid == "")     
  @" y0 u% l' X3 s. G3 N  {     
2 h3 T6 @( x' S0 Q2 P; m  alert("请输入中文昵称");     8 z; X& h; k7 E$ C, H: s( q# C
  document.sform1.chineseid.focus();     4 G: A, Y# P% u; {
  return false;     
+ L. V/ S, ~, n/ l, e2 V) w  }   
; G1 k9 Z. W% _5 ^ password = document.sform1.password.value;     ) o( i& D+ S9 y3 Y: f* U# n
if (password == "")     0 q# h7 u( ~: @5 f0 d: Z
  {     
' f; i9 j# a9 g$ {  alert("请输入登陆密码");     
- Z* r' D; D5 i* t8 c: _  document.sform1.password.focus();     
% \- m$ P" @6 ^) S9 U; r% y  return false;     / w% E2 W8 T3 @
  } 9 a6 p6 k* a( l7 C0 y1 }5 ]/ ?: A6 ~
password1 = document.sform1.password1.value;     
6 l& a/ @( A! J if (password>password1)     
: F/ K9 O$ G8 x% q& p2 R- t& `  {) X3 d0 g! z) X& v* i
     alert("重复密码与登陆密码不相同");     . R% R" g& p# m
  document.sform1.password.focus(); . b. A2 }" H) }* z1 H
                                document.sform1.password1.focus();     
# s9 r0 H' `. ]  return false;
. `$ R4 Q1 {7 {& n1 t  }  5 s( m6 g, z5 a$ U8 q# t  ?* H
if (password<password1)     
1 O/ L, X4 \' h4 K  i  {( ?, _0 {8 y- Z( N0 J/ M* g$ r
     alert("重复密码与登陆密码不相同");     
# b2 q! U3 M5 f2 x2 r  document.sform1.password.focus(); 3 o, C4 d; P( V/ I! z
                                document.sform1.password1.focus();     1 n9 x, D# q& n% t$ f3 h4 K
  return false;; U% d8 \) ]! E  x6 W5 G
  } % ?9 q4 s" e1 \1 I7 R
if (document.sform1.email.value == "")     
* ^. S. W: J  o  {     
! d0 ^. J/ H6 Z6 O  alert("请输入您的E-MAIL地址");     & J/ T8 G$ H. f3 G, \5 k
  document.sform1.email.focus();     
6 H* w! ~- p, w$ X- l2 h0 D  return false;     
& {( ^& N: z. n! W: U+ b* ?6 u+ S  }     / F# M+ u5 X' B! J: k# E
      ' b) Z. H) U1 b1 i4 V$ b
email=document.sform1.email.value;      * W, Q8 t' _$ d8 o0 i, ~8 ^
emailerr=0     # f& L. o* m8 Z1 K
for (i=0; i<email.length; i++)     
6 x* }3 a. F0 [7 [  {     8 @5 }* ^: E8 ]5 D6 X
  if ((email.charAt(i) == "@") & (email.length > 5))     
% k1 T2 ^6 l0 P0 w   {     
! Y  n0 b  e* h+ A. V- T! {     emailerr=emailerr+1     
( l# e9 ~9 K8 T  Y6 Q. J* ]   }     
, g/ Y( p, f1 I, L% i  }     
; h1 H6 `3 g* i+ k. Y8 P if (emailerr != 1)     
0 ~; w" h0 w4 @! \  {     , g( h: X8 v5 V. P3 b$ f
  alert("请输入正确的E-MAIL地址");     # v7 p5 k4 H/ X& z, O' a
  document.sform1.email.focus();     
7 `% R$ C) L1 E& P6 W0 ~& F  return false;     0 `8 J- O1 w/ a! }
  }           5 b1 r9 U0 J0 j7 q0 L) J0 q1 f
  
0 y2 I1 g+ \# [ if (document.sform1.checkask.value=="")
3 o9 j& e7 Y, V( ]' H* h- F/ h( \  {
: Z1 L0 K8 ^: K* j9 c; [: r; l   alert("密码提示问题不能为空");     
/ r: P+ O) u, I) d1 s   document.sform1.checkask.focus();     6 \% r( H) d- A$ n
   return false;  
" T. t' W! m+ ^  K2 B/ }) c  }
: B2 w: M3 y' Z. { if (document.sform1.checkans.value=="")
* S1 a3 ?  L, @6 E  {
0 Q1 C; v* [+ t# }   alert("您的密码提示问题答案不能为空");
/ `0 _7 X& O* c# R5 w* l% s   document.sform1.checkans.focus();     
% d6 p; r) \& {  d/ G7 J' [: g" ~   return false;  
; Y2 w% E% Y+ o0 T& b, I+ V  }
( Z4 \. N+ d/ Z return true;     
3 m; [: }2 b( Q: @+ E8 f     9 @: C( {6 @/ i! A% J
}
$ d" O: S' H7 U</script>

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