返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
7 s* P! P: _9 G, L* z9 H" o<script language="javascript">     
" V% L% Q- M) H0 L+ f, mfunction IsDigit(cCheck)     
4 e: Y% D: d; T1 f' i {     
/ v* l2 E, p* X- W return (('0'<=cCheck) && (cCheck<='9'));     ; w. e' F2 \; G. }9 @% V
}     
1 ~6 j  b" a+ @     & e* T, C% Q4 P
function IsAlpha(cCheck)     + S) U6 m8 s) n- U- }0 m
{     
; A( R& d6 U, ?4 d! h2 v. V return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     & r3 _9 z( |7 U  ^4 e& {9 T/ s
}              
( E' m( N9 R( H3 D      6 I* A2 d4 Q( b8 B' b
function IsaNull(cCheck)          ! h. @) y5 o, Y  F- V+ \4 ]
{         
) ?0 J0 i1 G: D, L5 q9 O. @' g, c. _+ Y return(cCheck != " ")         
' T1 H9 p0 w" @ }                               4 f/ h, k0 C. B( r+ r
      
! k9 G5 l! Q3 e+ j+ \: b  E. l% nfunction checkform()     + G: m& _, E7 k: i- t6 s' [
{ ; g! S! j/ p, W6 l7 E+ w$ Z
  id = document.sform1.id.value;       N2 z. a/ v2 P7 C3 D
if (id == "")     
3 N( G0 S) ?' ?  {     
* A5 [4 v4 i8 K( G  alert("请输入注册名");     5 ?/ n  l# i- Y; X% L0 C  r5 \% g
  document.sform1.id.focus();     / v* X. a: Z- j* x3 ~& ^: Q: Q
  return false;     8 s& L% u& D! `* }1 f6 P. F6 u
  }     ) m7 `/ W- S! t$ T* G- V
     
8 |. p) P" }( r! h/ T) G# m! C for (nIndex=0; nIndex<id.length; nIndex++)     
9 {/ L% Q) E  z  X; M" Q  {     ! X( n' K9 K( `: J
  cCheck = id.charAt(nIndex);     
6 e3 N! Z( m0 g5 v  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
6 w" T. Q9 a0 O   {     
! U" x  }" C  Q% H: e7 ?   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
0 \; V+ I) v1 e: p5 N1 E   document.sform1.id.focus();     
* R  t4 a2 K. e$ N+ j5 O   return false;     + {3 q5 `8 H, \: f; }- S
   }     1 o6 w/ c2 D+ K: h' n- [# ?$ G
  }
1 p$ I9 C) @, S/ G+ U  chineseid = document.sform1.chineseid.value;     
) O- p0 C6 W6 q, V( y8 q if (chineseid == "")     
: B0 c8 |2 w0 U9 t- d( n  {     4 h/ V, _( U% ]! m6 g
  alert("请输入中文昵称");     ( X, T- o& [7 t; B) [; w; H
  document.sform1.chineseid.focus();     
3 Q; u1 Z3 K( ?. ^: h  return false;     # c6 p& f$ }& q
  }    8 i8 U4 e. c+ w0 C& [+ y/ H3 b
password = document.sform1.password.value;     0 N& Y2 |5 \2 Z, ?. x9 l* E4 E
if (password == "")     5 x# f! D" \  `3 v7 N& G9 x
  {     ' J, H. Z% }. J2 t# z  E0 e
  alert("请输入登陆密码");     
. K, k: a5 _3 Z" p3 {  document.sform1.password.focus();     3 Z. b! h5 Y3 j* y& M; k8 f3 W
  return false;     
2 V% @3 W' X/ ]' ?# [  } ! g9 \8 W0 W4 m  Q! _% ~
password1 = document.sform1.password1.value;     6 E$ w8 L% I, D, {( C: W4 z
if (password>password1)     / ~0 H' r( ^& C* }$ j7 U1 n2 [! a  {
  {
1 ^" c  O$ t! M     alert("重复密码与登陆密码不相同");     
- a8 e, u  w6 \0 L, T4 t  document.sform1.password.focus(); * C& Z4 l) a: Q. U3 l
                                document.sform1.password1.focus();     
8 z/ i: @4 ]# b! {" F5 C( D3 F  return false;
# Z+ a8 D( M  z% a7 n  }  7 B: G; Z- Z7 S
if (password<password1)     5 T2 r+ @( w* O$ F, J& W* |+ Z
  {3 g$ h* ~/ ~+ o% R2 N+ x
     alert("重复密码与登陆密码不相同");     
+ d8 S) Q& l" L: R  document.sform1.password.focus();
" b) E* c. v3 E                                document.sform1.password1.focus();     
9 ?1 ^8 y; j+ {$ D/ T, {7 G3 u  return false;  ]. ]8 s$ L7 l9 |& W, X- k3 M
  } ( @, ^0 o7 n* F
if (document.sform1.email.value == "")     
0 e* N+ k7 M5 Q, R* n& A, ?  {     
3 }4 G1 A: u* y; q& R  alert("请输入您的E-MAIL地址");     
! S* @' \$ q: g1 k  document.sform1.email.focus();     ( m/ q3 |/ f/ O4 e+ r+ q3 Y
  return false;     
- h- E7 H: t& z$ o9 _  }     6 ]. ~6 U% |+ N9 g! V
      
. U6 w4 D& Q- O1 {) [ email=document.sform1.email.value;      " ]/ w. i& m1 b9 j# s
emailerr=0     
5 |: C" f* J6 u5 @5 f* R  q for (i=0; i<email.length; i++)     7 E! a) V4 W4 k6 E1 y" K4 b9 t
  {     
1 `4 u: Z/ C: B& c1 H7 z! X  if ((email.charAt(i) == "@") & (email.length > 5))     " F- d; _8 q4 F: r
   {     , |( [1 ~% e! e- L+ |* x/ e8 C
     emailerr=emailerr+1     
/ _! }/ R1 {* {) p, z+ c   }     / l0 |: _; `4 o# [9 K
  }     
. O' F, Z! O( ]3 S% l7 q if (emailerr != 1)     5 c# [# M  a' `0 Q4 `  Y
  {     
  R6 K- Z* B( t5 k3 w  alert("请输入正确的E-MAIL地址");     # C) C% m% A3 K/ a$ _0 V
  document.sform1.email.focus();     * q2 _3 e* U, }5 {# d/ p
  return false;     7 f/ {$ \4 S6 X$ r9 L
  }           9 M6 I) s  F. O( X- e
  6 {4 P1 ^! ^7 r0 f6 ~
if (document.sform1.checkask.value=="")
6 F3 m0 V! z0 m! x' R: V: I  {
/ R& X1 k* N4 {( ^3 n: s   alert("密码提示问题不能为空");     ! ]% R+ a+ s& ?, h" _! c" A4 ~( s
   document.sform1.checkask.focus();     - M3 T' Q4 k8 F8 x( ]
   return false;  
2 ?" L% c& a7 m# C: C  } / |) u+ p- U! ?3 X: _) }
if (document.sform1.checkans.value=="") ( T  P5 @% L8 y- S
  { : Q# Z3 T0 Z) I. H% Z
   alert("您的密码提示问题答案不能为空");   o7 a5 {# {8 Z  a
   document.sform1.checkans.focus();     7 I0 A4 R7 _, N
   return false;  
, H* J( J: J+ `; @  }: r$ p6 ^3 [% M
return true;     8 h% W9 Y! T) w$ b: Z
     
4 k- l- m' f5 b0 }- r2 V5 O}
8 A+ M' h0 M4 ~- k</script>

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