返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
+ O, E3 S% J5 i. F' n% _<script language="javascript">     % i% }9 U# d- r4 |; l# e
function IsDigit(cCheck)     
" ^2 d. H) J# ^! ^) S, ^0 W {     
1 \$ P- ]6 j4 C2 {6 ~8 R return (('0'<=cCheck) && (cCheck<='9'));     $ e3 w) u: }/ X, S0 }6 @
}     1 i' P' y3 `5 K* {, L
     
) Z2 w" x( q0 @: C( L, nfunction IsAlpha(cCheck)     + h7 G% g* Q7 a( I7 Y& t
{     
  d" o8 g- P9 F& K( u) T  L return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
- r+ l; c# s: z0 U2 i: ^" b# n }              
, t! @7 o" G2 f2 `. y9 H- t4 }7 {) X      : U. l* o2 _- i. T
function IsaNull(cCheck)         
) n) D8 s3 U/ G& f/ ^ {         
) Y: e5 w1 k; O& L1 X return(cCheck != " ")         , j# n9 i  k7 C& q1 j
}                              
' |+ B3 ~& U# _" K% F3 b6 [0 N      
2 H& F. |: @/ h% h. N4 k  c5 |- @) c1 lfunction checkform()     ; {7 w! ^4 Q2 r% L8 V
{ % b- p, V7 d- W) n. j( v0 ?
  id = document.sform1.id.value;     
: A, F' b" v0 o& o" J if (id == "")     3 Y/ f3 L, j9 o  P! F$ Z9 Q
  {     / |  `4 \* U' T# P
  alert("请输入注册名");     
  P6 s+ U$ i' H- S$ K( O$ A4 S7 a1 P  document.sform1.id.focus();     
3 R; l2 o3 l4 a$ R  return false;     
1 z" S' J# D1 U3 Z  }     
/ H! E+ e3 }3 {  s     
/ R1 Y2 Q& p& i0 t for (nIndex=0; nIndex<id.length; nIndex++)       R6 B, K& o+ a$ {  U, Z" f$ B- F9 E
  {     4 X: b) r) o( s; j( Y( T
  cCheck = id.charAt(nIndex);     & |: u; `: W5 S( v$ ~$ c- ~: V2 e; z, C
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     , I$ }- `% S' s
   {     
& n5 F) \' a& b, J" `   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
: |: {5 d' I! F  O   document.sform1.id.focus();     , p3 w4 U6 ]1 b. T# g! S
   return false;     
1 _" W. A  l: f; @: d   }     
2 x- ~# c# I+ D/ B, j' ]: |  }
( z3 }) i* w. D6 Z  chineseid = document.sform1.chineseid.value;     
5 O+ g% E5 w5 u1 A8 P# l if (chineseid == "")     , F7 f3 [4 w$ f, Y
  {     
' q& ~: g: A  K( J  alert("请输入中文昵称");     * J# S+ A1 g7 f: ~: Q; Y& L. X# X
  document.sform1.chineseid.focus();     $ N) w) y: \& O# I  n6 r9 f+ b( ]
  return false;     ( r2 i( r$ d3 T! L( e: t7 [
  }    ( M9 I; o; n5 Q  U
password = document.sform1.password.value;     
, J, P( @) L4 Z( Z% y* R if (password == "")     5 m% ~, R& P/ @4 ]5 Y
  {     
1 f. }" x3 ~; W3 \5 K* o  alert("请输入登陆密码");     
0 Y1 j; y. y( p( w4 X0 x  H  document.sform1.password.focus();     
' i6 K, q% n) ?  return false;     
$ l" E% \' Y* n# D* i2 ]  }
" s! O- ]; [# q0 V password1 = document.sform1.password1.value;     : P8 U$ O/ W6 O5 N
if (password>password1)     9 n# H/ g9 W" X4 c' e
  {
! F- i- G3 q. \' I9 Q6 X* K$ r     alert("重复密码与登陆密码不相同");       j# f, _+ U2 l
  document.sform1.password.focus(); ) p6 `6 s" M! x  Y! T, a
                                document.sform1.password1.focus();     
5 N6 w4 W% F, Y  return false;  G8 O) l8 ~# m! i
  }  
2 J; F' F9 U. T, Y4 `9 b; Sif (password<password1)     , W% P# Z4 g" x; J. f
  {
( {5 i* s  ]. X; z: y     alert("重复密码与登陆密码不相同");     3 a. A; o7 t1 n& l3 R
  document.sform1.password.focus();
' i( q/ p7 u: ?, N                                document.sform1.password1.focus();     
  s9 N; ]" u8 o$ M! `% @  return false;
; q$ b) I0 H# G5 N: [1 B1 G  }
) |9 H: b, X7 H+ b4 e: j4 @: y0 h if (document.sform1.email.value == "")     ; `- S( p+ h. N! e6 l" h
  {     6 m+ h) X, J) V) ?& ^; W
  alert("请输入您的E-MAIL地址");     7 D5 ?2 R: G; [' t3 c
  document.sform1.email.focus();     
! v) b  N: C; I) T0 Q3 K( z  return false;     
4 D' f0 x5 t8 K9 z/ z5 N  }     
) a: M$ P9 X5 t) ~      / L: i/ q$ {  i4 m6 M0 C! y
email=document.sform1.email.value;      
/ r8 J( u( B  o5 a emailerr=0     
6 Y6 @0 ]* g# M0 K& e* f! M for (i=0; i<email.length; i++)     8 C1 W3 y! S8 n6 ~
  {     4 `8 j6 C# {; ^# c7 d7 j4 q! H
  if ((email.charAt(i) == "@") & (email.length > 5))     7 N2 L' c7 S8 C1 p6 H
   {     
+ @+ L, G9 l' _* O+ _% a     emailerr=emailerr+1     4 y2 D- X4 b7 x
   }     
" o# m* s$ r! S# R' q/ K. N  }     
2 m! {+ P7 o) I6 w6 V7 v! o if (emailerr != 1)     . ~* R% h0 |# d+ s4 V( u# E
  {     
& ]/ G- U8 G4 Z& {7 }$ Y  alert("请输入正确的E-MAIL地址");     & z" @9 v4 \% Q. Q( `
  document.sform1.email.focus();     
4 v, i$ n, V3 t: o) H. p  return false;     
: J& j- R) L3 T9 r2 e, Z  }           0 c, }" [# g0 a9 M7 e
  4 m3 {, k6 o; x+ o- }
if (document.sform1.checkask.value=="")
8 g  @/ u" Z- h; M1 e+ A1 o  {
/ P7 l1 h) l$ c2 w3 u9 \! a8 D  n   alert("密码提示问题不能为空");     
4 a7 M$ ?4 S0 v7 F7 S# C   document.sform1.checkask.focus();     " N: x' _6 ?5 ~& ?
   return false;  " h& H' y4 Y0 e" K& s
  }
! m' I# I  K; Y( `7 I; G/ } if (document.sform1.checkans.value=="") " H( h- i# A- q
  {
; O2 R6 P- ~8 [. y  E; Q3 u   alert("您的密码提示问题答案不能为空"); ( a3 l; H& c/ J' e. D- K5 G- k4 C
   document.sform1.checkans.focus();     " X6 A1 B; `3 u/ I1 M
   return false;  
8 \% n0 c" R' e: b0 e  C1 Y" C6 b  }
4 l0 n9 W9 L! O5 A return true;     & V+ E& r* f, V- {4 s% `; X
     
3 v6 o+ b) C. B% @1 n! O} 4 W5 w/ n2 N$ w
</script>

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