返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:7 K( W: R3 H) R# r* }; ]
<script language="javascript">     # @$ v2 B& [0 k2 S
function IsDigit(cCheck)     7 Q+ t& B  M- Y0 m5 A; t( h
{     
6 a* j7 ?) \/ K8 b% f7 w3 U return (('0'<=cCheck) && (cCheck<='9'));     " U2 u/ }  M" K7 c
}     
. J* R3 x% P7 s. U9 G     
+ s3 v2 u7 A. r  w+ Ufunction IsAlpha(cCheck)     
" r! L3 f( u3 X$ e4 t# p {     # A! p1 o$ Y' s! b6 U
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     * _: o: S# P; \* z% A, u8 |) g
}              
& b; d* J4 h& t% o8 v$ B: l, n, e      8 d. \! U5 {  s% R
function IsaNull(cCheck)          * x: E/ V  t; D, W- r% p
{         
* Y8 f. D* i: @& S return(cCheck != " ")         
$ F0 H; i1 g: U6 d! \" F+ V6 Q }                              
, B: P3 B5 x- ?& o" F% V7 l' d      . _. n- }' J6 d9 d1 j* N  m
function checkform()     
* p) @, b5 s% y/ N' b/ r& d% k{ * m6 s3 ], s, D2 z# ?
  id = document.sform1.id.value;     
" F; G7 R& F! }6 U* [/ b if (id == "")     
- G% J- O2 W. E& ?$ \; M' l  {     5 J6 Z- E2 G. r) r( {& Q6 d; H* n
  alert("请输入注册名");     
+ _" Q6 R" h2 z8 y0 u2 a  document.sform1.id.focus();     
3 l( {! e! L$ E2 b7 N# G  return false;     % P% t8 r  u! J
  }     # J$ a; O' |; {& ?/ {
     
8 p* v, Z$ s  K1 K, i3 Y for (nIndex=0; nIndex<id.length; nIndex++)     - {0 V( h& D4 x" L( O! I4 N
  {     
- q3 i  P! O2 ?. S  cCheck = id.charAt(nIndex);     0 b" ]) H: |; D6 W5 [6 u+ Z0 O! T* a
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     3 C! H+ B7 g# S: }; J9 y
   {     & m, R  }- @9 E- w* D9 K
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     + S9 z1 b/ T* \* d# n
   document.sform1.id.focus();     % b, M1 I+ K: m1 e
   return false;     
; @# p) X! Q+ m$ d# U" x   }     
, C1 `  `0 ~: n' }# f( \  } + C2 F0 H, m8 B1 t
  chineseid = document.sform1.chineseid.value;     7 V- W5 m6 Y7 C; h
if (chineseid == "")     : d) ]& W- U5 j% y( ]# ~
  {     
1 X, w- ^) |0 r' C. }# D: q) U0 J  alert("请输入中文昵称");     4 Y# q+ O8 J; U) A( }
  document.sform1.chineseid.focus();     
5 q' l  ^0 H3 \) J& u' G  return false;     
. E# @3 Z7 f. ?) v6 i+ c  }   
! l/ T6 ~. g  C/ m, F$ h. X" b password = document.sform1.password.value;     / g3 f' D% ^" ?- b7 ]
if (password == "")     2 H% N& U  H: q! G
  {     
' g9 ?% P3 t& _, t9 S4 X/ \  alert("请输入登陆密码");     & ?6 `: V/ l3 Q$ U: t6 p7 {
  document.sform1.password.focus();       ~7 ?* v$ z! h! \( H
  return false;     ( c# P5 e# Y; V8 o
  } 4 k% M6 G  R% R( t* W. r
password1 = document.sform1.password1.value;     
6 K# A( Q4 b7 C4 ^" x3 K: X$ j if (password>password1)     
+ t* M9 e  J* q; ^  {
3 f: c% q3 h5 q3 d     alert("重复密码与登陆密码不相同");     
; K- t8 Q8 _3 x: o, k: g" U9 d7 g  document.sform1.password.focus(); ) h3 m8 @. k& C% Z  ]  y- g' l
                                document.sform1.password1.focus();     
/ \1 u/ m$ r7 M9 A" o6 v( q  return false;
; @6 r& K3 B( w3 L  }  
/ J9 ]  ]5 }5 `' \$ mif (password<password1)     $ C' Y3 x; ~, Z6 T  y
  {
' C0 i' Z% e5 i, |     alert("重复密码与登陆密码不相同");     & j+ P2 f5 P- x6 \
  document.sform1.password.focus(); , o- {! C# b+ o% y2 z  ~
                                document.sform1.password1.focus();     2 H4 O. k& p# t/ |/ }  a0 ~# _
  return false;
9 K1 ~, z; e7 N$ g# h, V  }
  P2 d/ r* a# {. B if (document.sform1.email.value == "")     - K' V' p0 z5 U/ H2 H0 I- X8 [
  {     
$ M6 ], N+ \% U: Q* X  alert("请输入您的E-MAIL地址");     / o3 S6 G7 w# e1 y. v' O8 [7 b5 j
  document.sform1.email.focus();     $ s7 j, o1 Q$ h2 h1 _0 @: W+ P
  return false;     
  |2 f( u. y- f+ T$ D4 V  e  }     % ^7 H& P2 [0 X+ k
      - |3 C' k, H% b- T
email=document.sform1.email.value;      * q' S3 J! b$ O  N
emailerr=0     1 P9 V( I; X9 I1 @# G/ u% |; S$ I
for (i=0; i<email.length; i++)     
) i1 S) a% t0 V" f) n9 t  {     9 ?. ~' F3 |/ r/ S) k) d
  if ((email.charAt(i) == "@") & (email.length > 5))     / n+ Q' N8 _4 E- F3 l4 Y: ]4 W
   {     
% x7 Q: a$ _# X5 O% O     emailerr=emailerr+1     ' y4 y, r; T% Z& E, @/ E1 o
   }     " q% q: u. o) N8 o" C
  }     % D5 W& Y( C# v6 O' V
if (emailerr != 1)     
8 A" f* E7 @* X* Q, X  {     
1 {1 D: ]4 r) e9 p' \6 a8 X  alert("请输入正确的E-MAIL地址");     6 [& O- f7 s  ?5 c9 |4 M
  document.sform1.email.focus();     - Y' a! U/ R% a0 Q
  return false;     2 u4 K$ p5 U; c/ X: A  h2 n
  }           
# c+ C* N8 Y7 g1 W  i8 D7 v  * t& S0 z" ~" d" H9 U( c4 q$ M
if (document.sform1.checkask.value=="") 5 G+ N) s4 O/ ~' E* q& _
  { # `. B& }7 [. D
   alert("密码提示问题不能为空");     
! F, O( |/ D# J" ^# t: X- O9 G0 _9 U   document.sform1.checkask.focus();     * D  B) O7 A6 w5 I
   return false;  4 S$ O' I) F& G+ E% q0 W- }4 V
  }
0 {/ h6 {6 W: ~8 e if (document.sform1.checkans.value=="") ) ?' h7 l6 q8 ~& N# P
  {
3 x# j, @0 Y  d! g8 S   alert("您的密码提示问题答案不能为空");
" n0 a; k' K1 H- j3 p; Z1 w   document.sform1.checkans.focus();     
7 I8 i) Y5 U3 @3 K" N   return false;  ' q# I  W+ m  L9 g0 v7 E4 Z# }- Z
  }3 G! Q8 g( [3 ~6 P" G( W9 b
return true;     8 U- a7 u# \6 L9 }# N& R8 ~
     / Z2 ?0 ~7 m, G' F) m& {
} # j6 e& ~  L! O& T, I2 M$ R8 x. P
</script>

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