返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:- h8 A4 O- v& e5 R
<script language="javascript">     
( A7 T" r: {9 V- Z8 |) Ofunction IsDigit(cCheck)       F2 R2 ^" h$ {8 P. I
{     " s- C% f, z4 P: K
return (('0'<=cCheck) && (cCheck<='9'));     
& r, d' W8 F3 g$ C: @ }     
# Y8 V- z7 }0 F     * O' e/ g* c$ `; b* J  g- V% v
function IsAlpha(cCheck)     7 P" Q2 C1 V* y5 a. m1 o1 a) b
{     2 p. V& M! p! Q0 K8 F2 C
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
: }4 S& H1 y* P6 b2 [, n }              $ p- H, \8 g3 ]  j# u* c
      
/ Y+ x8 U1 q: Yfunction IsaNull(cCheck)         
: ?' P$ q! ]! s' h {          6 \4 s; w+ N) _4 O3 x) q: q
return(cCheck != " ")         
: _8 a' g+ a$ r7 }2 h' a, v }                              
* }" B9 G9 q5 [  D7 A5 [      $ L9 `" `4 u# G
function checkform()     # N4 c& q8 K8 x
{
  m. D# O: i" D3 x" {  id = document.sform1.id.value;     - }" z" R+ j& y$ Y6 e3 `
if (id == "")     5 h2 w, V* u! a. l& v2 T
  {     
7 H4 I5 }4 F, T1 V& H. c2 q  alert("请输入注册名");       u) C$ ?' V) |. y9 c: T
  document.sform1.id.focus();     
# X; J$ e3 h- C8 K0 m3 o( e  return false;     , T3 ]5 k( {) p) N& t# t7 y1 M
  }     
( A& V! v5 H4 `     7 ~- U. G2 K2 k! B7 Z
for (nIndex=0; nIndex<id.length; nIndex++)     4 x3 m- g2 p  l& l, @& m1 v
  {     " `; o: d( s3 L) {
  cCheck = id.charAt(nIndex);     
; g  J9 Z0 x5 w; D! U8 V. ]  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
9 i$ k3 L3 s. b) \% Z   {     ; V; q8 O3 y( P' k. r
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     . }' K, C9 a5 I$ ^8 s6 j! i
   document.sform1.id.focus();     ( C; s$ c6 ?( ], v6 ]
   return false;     
7 j- F* n" p9 H/ m; F+ W   }     
% f: @1 T8 a5 ]  } , D, s) c# R1 Q' y
  chineseid = document.sform1.chineseid.value;     # ~  j) l- x1 `9 w; T" q) y
if (chineseid == "")     
( ~3 S( o/ v! B, z: G* u+ w  {     
/ }! M0 U/ X' k& r/ B/ |( k  alert("请输入中文昵称");     - |+ \3 P, u6 i/ K* S
  document.sform1.chineseid.focus();     ! ^7 ~& q3 _) G3 ^, n" z$ ?# {
  return false;     
# Y* \3 I# G$ o% a( n  }      a) I$ }1 C$ G$ R' U! X
password = document.sform1.password.value;     " h- s# `( D; W" P+ e
if (password == "")     
8 e3 q7 K; j' e, U5 [" D9 D  {     
* |* k2 S; o1 c  x  alert("请输入登陆密码");     ( H- O$ K+ {/ R
  document.sform1.password.focus();     8 F6 M, O' Q; W
  return false;     
$ E. B% D5 v9 ?* `  } # g$ \) O6 I3 M% f2 }
password1 = document.sform1.password1.value;     . ^, \6 _" X! r0 u
if (password>password1)     0 _7 k% p5 V# T  s6 J! T! [! G
  {
: ?5 e/ P8 ]2 F     alert("重复密码与登陆密码不相同");     ; _6 G1 r8 ^* `* P
  document.sform1.password.focus(); " w" S) E1 @) d$ a/ w; U
                                document.sform1.password1.focus();       j, W: F4 _, z( V1 g
  return false;
' l" N- Z) T! i+ K( v  }  , O+ O( }; j3 X7 m" ^  [1 w
if (password<password1)     - ]. Z: I8 `" d" L3 G
  {
7 \0 }4 T: j9 P4 \: X) Z     alert("重复密码与登陆密码不相同");     ) L/ g! S: ?3 q$ H2 f7 U
  document.sform1.password.focus();
) C4 r9 o+ s6 F1 Z* d. p                                document.sform1.password1.focus();     
% ?9 E7 e# l1 u9 y: G2 n  return false;
6 o( c2 d. J" A" l. @& W! _  }
9 f$ s# _6 D  _  E, @2 B: ]/ I4 A if (document.sform1.email.value == "")     + W# ]- ^# }3 A( A6 T) ]. E
  {     : E1 |6 N& Q  X5 K
  alert("请输入您的E-MAIL地址");     2 M( R/ Q" s+ h
  document.sform1.email.focus();     0 g% f# Q$ o* y
  return false;     ' R6 b2 S4 H# `# @, }
  }     
$ r, B* ?; z3 o      
; `$ A! ^: y+ e5 m6 O. n7 [/ s email=document.sform1.email.value;      
( z* p2 j0 D; R6 ?  _! C emailerr=0     1 s+ x: E3 ^: E& X. n' Q
for (i=0; i<email.length; i++)     
7 x+ ]5 W$ p# L5 w# n" ~* T1 y  {     + Y* @! G1 Z" j/ Q: u+ E
  if ((email.charAt(i) == "@") & (email.length > 5))       o8 y' |1 d% l
   {     ( B( [# V) F9 k/ K( {- c& H
     emailerr=emailerr+1     ) m& D( h" N" T" h
   }     2 Q5 k2 N3 |2 l5 n2 P
  }     , M& @: L1 V! |6 z. M' h( b  C& K
if (emailerr != 1)     * k) F! \, W/ A( n- K$ a/ [
  {     
: \( `% l! u: y* u# p/ i* N  alert("请输入正确的E-MAIL地址");     
2 |6 U" N/ ~. m: M. ]# W4 a9 T: P6 c  document.sform1.email.focus();     
: u/ \4 e/ J2 @  return false;     8 f/ J) I8 Y. N0 l& u4 k
  }           2 b: f- ]; r" g6 r3 U
  
6 i# r- p$ H5 Y8 b4 G/ R if (document.sform1.checkask.value=="") % `3 l; N) x1 I0 h# x& m! i" A
  {
) D( P: N, ^6 i2 W) C* A   alert("密码提示问题不能为空");     
. n$ x( c8 j" ~# r& m1 Y1 f   document.sform1.checkask.focus();     % J9 ^3 q: r, x2 g  T! M1 {- r7 \
   return false;  ( G7 O* {# g# B+ k( d% g* [( K
  } $ z  c7 }9 ?/ z* @& Z
if (document.sform1.checkans.value=="")
, r" E1 B' I3 t- J* C% L# c; p  { 7 h" P4 C4 t/ e8 n
   alert("您的密码提示问题答案不能为空"); 8 ]5 K* p- z+ ^3 D; j' p% S, U
   document.sform1.checkans.focus();     
0 T/ z3 g/ U1 ~: t   return false;  ) M; i1 B' K) k: G4 v3 H! E
  }- N4 L! d/ U( \( L
return true;     / \3 V& w+ d6 g9 G$ ^
     
4 G6 N5 q9 @. k" O3 P- k1 Z! N} ( U: b; f! ^, P6 P$ |
</script>

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