返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:# p' Y" S7 c, }" w! Z
<script language="javascript">     ; j9 Z% i6 R. a6 v$ E
function IsDigit(cCheck)     
9 N3 ?3 c# W( V8 i+ I  b$ N& D {     
! L0 R$ b8 l, Z; X. r return (('0'<=cCheck) && (cCheck<='9'));     
0 c! O! d+ B& [7 N, y }     
2 v) Z2 f, \1 |$ b, z* i) T0 V     
- y. v" H) }4 b$ f  Cfunction IsAlpha(cCheck)     . c1 Z! y( f4 o  s) h; u
{     
2 X9 M7 C6 p, c7 @; Y+ r& b9 z return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     . S& O8 V8 F. ?# P
}              # p' ?6 A, p- J* u; s4 C. h. c
      
; |6 }' E' D( J0 afunction IsaNull(cCheck)          ( L8 W! O, P% p9 Y3 T/ \, K0 N+ @( f( N
{          & f. D  t. X0 [& H9 @
return(cCheck != " ")         / w: M# ~" h2 h( t8 N
}                               . S1 [# I& n! z9 [# t$ i9 @: i
      
' ~7 |. q; C1 V$ ofunction checkform()     " q! H7 S6 j" y. W
{
1 M; ?* C- o4 o1 ^  id = document.sform1.id.value;     ' y, Z# z" p2 C( L$ p
if (id == "")     
1 Y3 Y( G- G  o5 z: W  {     
: F# ?& C+ {" ?/ h, ?+ H, ~1 h  alert("请输入注册名");     % F; ~* s$ k8 K4 Y! ]+ g
  document.sform1.id.focus();     
8 h9 d( m0 S, i9 ^( l8 X$ v  return false;     
4 k+ M; e1 W* S" H2 n  }     2 N. @4 I' o1 t9 x& e0 ~' h. ]
     
- a4 H9 n6 ]) N5 J, S for (nIndex=0; nIndex<id.length; nIndex++)     
9 W. s+ ~' K8 v) h  {     
; L% G4 [3 |* E5 ]7 @9 ]2 K5 _  cCheck = id.charAt(nIndex);     % u) m* g  _8 f1 s9 j
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ) x3 i  `3 G. G. U5 G& `! B9 J
   {     : e. A0 Y' [7 c- |. L5 Q, v
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
7 _0 L4 k* w- l! `2 }2 j   document.sform1.id.focus();     ; t0 r* W' H1 v7 [: d# G5 u% L
   return false;     
4 j. n. E7 e$ h+ L9 T   }     , c5 Z$ Q0 h0 s1 k
  }
! ^4 T9 K4 U3 ?2 {, a+ C  chineseid = document.sform1.chineseid.value;     
; c9 n/ }2 A% R9 n* U% ~ if (chineseid == "")     
# f, Q0 ?- r& o; U* o& R, g  {     ; \% C( }% e" g6 f- U$ ?5 y
  alert("请输入中文昵称");     
% e" v1 G  W4 O  document.sform1.chineseid.focus();     - m/ \0 j0 W, u( Y+ D; h# l$ g
  return false;     
2 H+ X% B& R/ a, e9 J+ a  }   
) W2 i; E6 n" c; T. M password = document.sform1.password.value;     $ E+ a+ ?! l/ }/ F
if (password == "")     
5 Z$ l/ `# y! @' E9 ^6 K6 H  {     
6 M3 @; V% f, c  alert("请输入登陆密码");     
8 z. W9 w  x' v- t/ R4 S  document.sform1.password.focus();     : e7 V  G" \) ?% }9 x
  return false;     ) U, A% s8 M$ x
  } ( d# G. S; \# s6 v& ^3 [7 W
password1 = document.sform1.password1.value;     
0 W5 D, k. x, x/ Q if (password>password1)     % D$ P$ C2 N9 w% ?
  {
" j8 _# |, p1 T$ X4 U. u7 q     alert("重复密码与登陆密码不相同");     & U' x% G( p9 A, m9 y2 |7 A
  document.sform1.password.focus(); 0 J5 H" {) n# [5 O  \
                                document.sform1.password1.focus();     7 o+ E) a, l8 q7 G
  return false;
) ^! Y! I) ]9 ^: N3 M; A# I  }  & E9 ?! J1 u9 w2 g
if (password<password1)     
5 D- B, R+ r. R0 y6 c5 M  I  {$ u  l/ w' B0 G% f  V1 S
     alert("重复密码与登陆密码不相同");     7 g& ^0 L% F1 I  @# P! y
  document.sform1.password.focus();
+ \; V5 @( b( N( @, l7 I                                document.sform1.password1.focus();     
6 d% S% \6 ~/ X  ^! d  return false;& F5 h/ {% p$ \" ]
  }
" ~8 U2 _) |7 u if (document.sform1.email.value == "")     7 w5 S+ m1 [9 p! f; O  `1 e8 D
  {     ' _4 h" S) C4 S2 ?
  alert("请输入您的E-MAIL地址");     
6 W9 e- k. x+ A# l* x4 D  F  document.sform1.email.focus();     " ^7 I+ N- q4 g: y' W1 ~# J
  return false;     4 c8 P! M, N8 D
  }     
8 G, o. o6 ^* t& y8 B      
' ~( H( J0 T: Q; `, ^6 i7 L- _ email=document.sform1.email.value;      * l& i; Y+ n6 Q0 P0 R8 k
emailerr=0     9 i& P# k2 _/ u: ?; A- r
for (i=0; i<email.length; i++)     + n# @" M8 `& N% Y4 P# D
  {     6 y: x0 r* S5 S) u/ x6 {
  if ((email.charAt(i) == "@") & (email.length > 5))     + ]. z4 j* j& N$ V/ ~2 ~3 {' u
   {     $ H* X$ P% x2 X
     emailerr=emailerr+1     ! B" w. ~5 v* V7 J. g2 ~+ N6 I
   }     5 g& s+ `" K8 s! B5 `
  }     
. A% {6 `; w+ J/ w if (emailerr != 1)     
& Z- C( x2 W  R1 b% y. @4 r  {     
& C4 \; X/ L# X7 c; G  alert("请输入正确的E-MAIL地址");     
- x. J5 }! B: F0 P3 g, a8 h1 W- b  document.sform1.email.focus();     
  R, M+ v+ S' E4 L& k/ v7 b. ]; |* P  return false;     ; G. m+ m' [- i0 F) J6 F2 E
  }           " s) n- j) K6 m- _4 }2 M& b9 r0 K
  
9 `# K6 ?; P+ L. E) j if (document.sform1.checkask.value=="") % s. Y  n, E$ w
  {
) P7 H% F6 T* V: O4 c9 W   alert("密码提示问题不能为空");     
  R* L1 O- f* J$ ^5 T6 ^   document.sform1.checkask.focus();     
; o8 C( x# q, t, g$ |* z2 K+ N   return false;  ( _2 [5 w6 f3 x0 W
  } - c3 E2 v6 G  b. J; n* p7 ?/ E
if (document.sform1.checkans.value=="")
% q% ]' J% ^7 E3 q1 u' o! H  { ) `* p; B" c9 E: M3 I
   alert("您的密码提示问题答案不能为空");
  S) m  ^# v7 J) O. J3 `4 ]   document.sform1.checkans.focus();     
2 |' g+ E: {& X4 W, t3 n: n$ s   return false;  
" K, Z2 b# s- Q, s. d  }
. o' t3 N, ]& u* `8 ~6 C return true;     ( M, y3 V, p+ ^' _1 d9 E1 ?
     ( i4 k; q, s' ?& i
}   H8 c# ]  y: y" w9 w8 z' x8 H' F
</script>

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