返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:6 B$ z8 Z. }) {& H& F2 U: k
<script language="javascript">     
2 J) R% E0 G$ U+ X( b' qfunction IsDigit(cCheck)     + q0 S  N4 Y3 m& y9 \
{     
% j/ N7 Q$ P4 e3 B# z return (('0'<=cCheck) && (cCheck<='9'));     % i5 z; I3 B# g3 p2 V
}     0 z) J9 s. n. i
     
/ o/ A" i1 B: n5 v- |! ~function IsAlpha(cCheck)     1 j( l  J1 `( C
{     2 c. m3 d& h' v0 ]) C! U9 g4 g# j5 w
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ' t8 f. _/ i* n4 C7 {7 [! I  O% U
}              
0 Y6 e4 ^# E+ t& Z, p      
( r4 U) R. D$ b( y5 F  |, Q: I& l! Cfunction IsaNull(cCheck)          0 Z1 q5 ?- \5 f+ z  k6 [2 ~/ a
{          # Y8 W; @& X; ]! A" e% I
return(cCheck != " ")         " R( r; t. }9 b" h' b- W! f# g- `
}                              
) s6 _" N; p4 Z' z# e8 I      / C4 N# s# }' |2 j8 e! z
function checkform()     ) C  m" K' L% `( m4 b1 Q: K
{
$ H8 Q3 Y. N: q  id = document.sform1.id.value;     
: e, a: a, E* a/ V1 m8 \! f if (id == "")     9 E/ B( d1 {$ `% }, l5 m
  {     
2 h  v9 S: w0 G2 N  alert("请输入注册名");     
0 K* ?/ Z' T# R8 ~: U1 X  document.sform1.id.focus();     
- ^1 S' H$ z  O( V# t" C  return false;     
* n1 L$ m: O1 C2 N8 c4 Y  }     
" z9 D& I# ]% v" H7 R7 u6 x     , I. o8 v/ I3 Y; w1 L" c
for (nIndex=0; nIndex<id.length; nIndex++)     
* L$ H: s- ^4 u$ ?, d  {     9 I. R7 D9 v# J9 r( ?5 ]9 o2 z
  cCheck = id.charAt(nIndex);       g- O: ]; F6 m& V) a
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
3 g8 N: ~1 }1 d9 d0 m  G- {   {     
: J6 n( v$ q" z) K7 O   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     0 Y  L$ I/ f- k
   document.sform1.id.focus();     
" v% B: p- J4 b. W/ |+ p* z, E2 T   return false;     
! a) Z1 _9 M+ x$ B' I; \1 q   }     3 f9 Z1 @! b7 k
  } 1 \8 ^+ {9 E3 M; d1 a
  chineseid = document.sform1.chineseid.value;     
' \5 g8 A/ X$ V0 j; U' c$ ` if (chineseid == "")     / J$ J8 }& T% n, M" L+ b# ?
  {     
! ^  _& `* [6 n% s  alert("请输入中文昵称");     
7 Y5 b: U# ?! o  document.sform1.chineseid.focus();     ; o1 a$ K! h, g' W+ |
  return false;     ! M  A# a, F0 Q
  }   
5 Y% U6 W- l1 y4 w password = document.sform1.password.value;     " X+ c" w1 C% g, h$ Z2 ?
if (password == "")     
5 t+ X, z- N9 y( A9 W  {     , E8 _. U* X: f* Y5 u
  alert("请输入登陆密码");     
( t8 q; P/ i/ I4 r  document.sform1.password.focus();     + d/ {/ A! I4 C' r7 @
  return false;     * w" [- Y: Y1 s4 x( y
  }
! [0 [4 }+ p* M* z% ~ password1 = document.sform1.password1.value;     
7 t. y& ]- G, h6 A! W if (password>password1)     9 x) D5 m3 g! {  ~. R  |' p6 {- K# A
  {/ J* K/ p. |$ U* x! C
     alert("重复密码与登陆密码不相同");     
1 s) W4 n8 ?; h! p: s, f% W: j  document.sform1.password.focus();
( X' p& x- k% d                                document.sform1.password1.focus();     
$ y% c6 ~' i/ |( m) T& e  return false;
+ j4 D/ z/ z0 B$ C  }  
% m; M0 O1 W% I3 A* e4 D9 dif (password<password1)     2 V+ I7 q9 c+ M. t3 @6 o: k/ p! T
  {# x- d/ N% i8 E/ L" L
     alert("重复密码与登陆密码不相同");     4 g( e4 L. o: F; [$ U- h
  document.sform1.password.focus(); , k4 L) m; z" M/ z: m! x' m/ |
                                document.sform1.password1.focus();     + S& p+ T9 Q- w- e; |# x- {6 ]
  return false;
+ K, c) S0 G6 R: O  } & L' [% M2 C/ n5 s+ @$ W, J0 v
if (document.sform1.email.value == "")     9 C9 n3 z7 a! f3 }  F6 W
  {     $ Z5 X# M0 s) K  J' N9 o4 `: f
  alert("请输入您的E-MAIL地址");     ! K0 l( G# j. I. O; t" Y
  document.sform1.email.focus();     
6 A/ v3 E! d- A4 C# C$ q2 b  return false;     8 s( @+ o9 P, J
  }     & W, k4 h# o5 s$ U# s: K1 U$ W
      + y  U; F' f# A9 h) p, c6 s6 p
email=document.sform1.email.value;      1 o; y' ^+ L! ~1 `  q
emailerr=0     " s& U0 I3 D6 h' t
for (i=0; i<email.length; i++)     $ A9 ^* N! C+ q3 c' T8 p" ?
  {     
; t  ^2 _7 r0 W6 e  if ((email.charAt(i) == "@") & (email.length > 5))     
9 R) Z! G$ v2 h7 q) Q: G5 F   {     * C# y7 a1 V" \$ |
     emailerr=emailerr+1     
% ~" e- q/ w& W+ l% u   }     
8 d7 e& g2 l2 Y/ j' H- M  }     
) [0 J, N9 y& ~$ \9 E  `3 t# C if (emailerr != 1)     ' _4 w/ l* G: m; u
  {     ; ~, Y6 `5 p* P% ^
  alert("请输入正确的E-MAIL地址");     
" Y& G6 s4 q( n) [* f$ [  document.sform1.email.focus();     
" k7 [0 ?1 `+ e: P6 ]  return false;     
9 s; x1 g( E2 l  }           
9 V/ l- i; ~1 j$ s- V0 R  * g2 ^6 o) g! J
if (document.sform1.checkask.value=="")
$ b: f+ p! ?, ]2 E  { % J% e1 }; }0 U1 v4 d  m
   alert("密码提示问题不能为空");     ! C' F0 q" Q4 h; D% ~
   document.sform1.checkask.focus();     
3 A! B9 N& G9 L2 q+ ], t. W  w2 S   return false;  6 m- P' O8 ], ~- G7 F* F- [: V
  }
5 _2 C7 |2 ~7 _ if (document.sform1.checkans.value=="")
9 R  i5 p% H; B0 [$ n  { # L* z6 F# R- }- q& o8 `
   alert("您的密码提示问题答案不能为空");
" F7 j/ ^* D' o2 A* B- ~& }8 h& f   document.sform1.checkans.focus();     
- Q0 H) w2 n+ g: n7 V/ ^8 Y   return false;  
3 Y6 g2 \/ l0 x; W  }
3 W/ b' N: G! b1 N return true;     
) ^+ P. i* D" m# O     ' E2 g. k9 S+ g8 a' g
} * v- c" Z- c. b. Q3 }9 l+ d5 k
</script>

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