返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
4 I% Q/ |  k$ t! l; J3 @<script language="javascript">     
6 g* D# x1 c" \# v7 Rfunction IsDigit(cCheck)     
, R% B( {4 R# a+ U2 e1 }3 J {     
  i# L( @5 i2 h, h3 B return (('0'<=cCheck) && (cCheck<='9'));     % q7 u" g: U1 S* Y( E: F
}     & B/ @4 R1 i6 l( y8 q% \
     : O6 h9 S# b0 u% T% N& B
function IsAlpha(cCheck)     
/ m# W; V- E" u& N) o$ x8 a {     
2 j+ }# k/ M) A" Y2 b return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
9 v! b7 \: ?0 L6 E$ Z, P. U- n) E }              
: F' Y& ^( x% m6 ^' ~. ~      * |% y: @6 y/ D
function IsaNull(cCheck)         
9 @( w" B% w$ `) H: U! J: g8 s {          - J2 G# X3 k6 A5 x: N' J
return(cCheck != " ")         
  \7 t6 h# K! ^4 G }                               2 s: _/ x; I" @1 C
      
7 U0 P. V. i  b) ]4 W" D' mfunction checkform()     
! k9 F3 x2 y* }0 J0 \, p{
* r% B7 ]8 M* P9 r/ e8 Z# }  id = document.sform1.id.value;     
) w- |& i  B5 L5 h if (id == "")     : l$ H" l* ^) y+ |8 ]) a
  {     
$ a# E5 k" D6 M) T  alert("请输入注册名");     
" U/ b! O& j" w5 i0 {1 j  document.sform1.id.focus();     % v0 n4 F! m* a% Z* c
  return false;     
. Y) @4 U; x) y7 T3 u  }     % n! ^) N6 E" B% o/ Q' I8 m) e
     * E: I& F) O8 v! i
for (nIndex=0; nIndex<id.length; nIndex++)     : E# D1 l6 z* e3 m3 y! {- A; d
  {     
* W/ \& {* X8 I7 f1 u8 H  cCheck = id.charAt(nIndex);     & F2 I2 k& n# A9 l( {" D: D: I
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     # o& p/ W) ~$ Y+ d1 O
   {     
. O8 `  {4 u/ |* X5 Y   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
6 L/ ?! a4 ]. B1 g) [" H   document.sform1.id.focus();     3 I$ g& J- S' s. A
   return false;     
$ j6 Q* h" ]  V1 n  L) n   }     1 w9 i! e- g3 E
  } $ y( Y# ]4 a0 G, D
  chineseid = document.sform1.chineseid.value;     
% k" {4 b$ c( C if (chineseid == "")     
. z8 P* J( K" @/ o  x  {     5 ^/ {* W) a6 a5 h6 u
  alert("请输入中文昵称");     
+ R1 B+ E9 v) ~$ R' g  document.sform1.chineseid.focus();     1 G# L% y& b. Y: |" M% z$ _
  return false;     
. U1 s! p9 b+ D0 J6 H6 x  o  }    & b. ]: c; u1 X' Z* @5 l  z
password = document.sform1.password.value;     6 }0 b# s# p, }0 V: J/ B
if (password == "")     ) t& R+ X1 m5 ~# j3 c: ~
  {     ( m3 i3 h' O7 M0 F
  alert("请输入登陆密码");     
; J" \; Z/ t. F# k+ B, P% r  document.sform1.password.focus();     
( @( M/ f) K1 O9 L" m  return false;     
. [1 k- W1 L4 K1 A! P6 I" m  } - l1 Q" D6 D- ^
password1 = document.sform1.password1.value;     
' C# t' ?& _. @2 P9 U- n" f if (password>password1)     
7 _" D$ |2 H0 V3 @/ A) v1 f  {) S# A; Y# ^/ @  y$ n
     alert("重复密码与登陆密码不相同");     $ N; ]' H* e8 }9 z: x- ?+ h
  document.sform1.password.focus();
% I- x, d; S; @, H; x- s6 F; J: ~& z- u0 Q                                document.sform1.password1.focus();     ; |5 a2 v: e( U7 \" ]+ F7 B' D9 v
  return false;
6 |% a9 ?! h( |" y4 k  }  4 @; R& o6 \# Q6 g% L7 a! w
if (password<password1)     5 r- _% s' b2 G$ ]
  {
6 s( k4 N7 E* s% E' H- Y. ~     alert("重复密码与登陆密码不相同");     ' n9 Z9 J# z! c- N
  document.sform1.password.focus();
4 L( d9 v- P0 ^' x                                document.sform1.password1.focus();     # A8 S5 y- Y# F- o3 z. u
  return false;! e7 g7 b' }! \4 m$ M
  }
/ g3 {+ J0 J' T$ @) p: S if (document.sform1.email.value == "")     + w( _, [* _. v6 t# U1 a' S9 [7 c
  {     
4 t. x- l* k9 b0 U5 Z3 t" d6 L% l0 z  alert("请输入您的E-MAIL地址");     
/ L0 f) _3 z* Y# g  document.sform1.email.focus();     
1 X; o- v3 }+ d0 x8 M) @: J  return false;     ( _6 d) Y+ l; A
  }     6 R  j& ~- M+ Z$ ^: x- J
      
4 W. g3 ^& M7 B1 o1 z9 M email=document.sform1.email.value;      
. f" H3 @9 Y( B( | emailerr=0     
0 I* v# }8 d( \1 I for (i=0; i<email.length; i++)     # w% O* S- _6 l. a$ e4 h
  {     
3 i! c* T* f/ o  if ((email.charAt(i) == "@") & (email.length > 5))     , W+ D( O. h7 L7 o
   {     6 u  }/ c, {$ C
     emailerr=emailerr+1     
) o, b) R/ m0 Z- o; T   }     " I5 @7 e! {% R) u; {" ~
  }       d! J4 w- Y; z7 h
if (emailerr != 1)     
$ w+ s% G* [# M5 d$ d  {     
0 @* t2 V# `, }" e0 |  alert("请输入正确的E-MAIL地址");     * |2 j+ P1 x; b) n9 r
  document.sform1.email.focus();     
: g+ _% e+ q$ g3 }; Z  return false;     ( F% j' {: k+ u9 t$ i% W
  }           
3 G$ Y. l! F% b* i' d8 Z: \  % m" A6 h5 T$ F6 W4 U
if (document.sform1.checkask.value=="")
7 v5 I9 h2 L+ X  {
6 v3 w# D9 M, N8 O2 z5 ~$ Y/ `3 Z   alert("密码提示问题不能为空");     : u# B( a4 d- V+ R8 k5 n7 ?  \& i1 v: y
   document.sform1.checkask.focus();     
+ b, j, `9 P; O3 R% p5 L4 m   return false;  9 l0 l6 q/ f; _' `; F5 a
  }
: R* u4 z/ `& ] if (document.sform1.checkans.value=="") $ W5 f; {  P" n
  {
3 U4 k- w! ]3 T6 {1 E& T9 a   alert("您的密码提示问题答案不能为空"); , [' D6 }* L# H, {
   document.sform1.checkans.focus();     
( F( }$ \$ ?5 |+ U   return false;  + Q5 [) v  ?  I+ u1 |- \+ g* J& I) P) S
  }- i6 _' f7 T- Y, p5 G( P. r7 o. O
return true;     , f) A+ ^$ R- @: x# A1 j( [
     
2 v, R3 G% t2 |" u} 2 |' v" S. s! h& J8 O8 ]
</script>

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