返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
! W9 ~4 b* D. f: H<script language="javascript">     + ^7 d1 Z% E( _: ]
function IsDigit(cCheck)     
$ b: y; G- O" t% J {     % k1 K2 ^. X, _; o  U
return (('0'<=cCheck) && (cCheck<='9'));     : f8 Q0 ~* I( ]' s6 b
}     # R, u; M/ k' e6 ^1 a. I% f" F, o
     
7 w4 z* ?- O& d# k( g+ Ufunction IsAlpha(cCheck)     7 s& j  G$ ]3 }' u7 L
{     9 i9 `4 K8 v1 _" J1 [
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))       o9 V0 p, L' z
}              
2 j: M6 V1 B9 b+ G- Z; r      / R  Y3 }% p7 j$ U9 v- R, b7 T" A1 @
function IsaNull(cCheck)         
# K) H& S+ c* a {         
7 b& ^2 y2 E& H* B6 X0 v return(cCheck != " ")         9 E3 {6 y" [. P7 ^. F  M
}                              
2 B; U4 |6 B1 w      4 }4 Q8 @7 S6 l! h  [* D  ~
function checkform()     
( Q+ `- e3 b7 E; Y% ^{
7 I2 C6 R' g- ?4 ~( s  id = document.sform1.id.value;     8 }- d5 m' V* b! t: ?$ c
if (id == "")     
3 `  J. J$ q9 ~  {     
" f; R+ I% r+ y( h% W: T  alert("请输入注册名");     . m$ S5 [# O0 t/ y. k
  document.sform1.id.focus();     
. E# c4 K# v& \2 A* @, x  return false;     
) n7 s* d: [( G: ~  }     / \6 n! g: E, l0 o. p% w$ ^/ `
     ; d7 K3 N/ p! n, M
for (nIndex=0; nIndex<id.length; nIndex++)     
2 h- K+ J3 N) u0 S' r5 G  {     2 D0 X1 x% c7 N9 Q/ l. b
  cCheck = id.charAt(nIndex);     
4 _! {! s  @: w# p  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     . h3 B% F6 g2 t* v
   {       A6 t6 @) N( c5 X* ^% v
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     3 V1 i; a: t) T' [. S
   document.sform1.id.focus();     % g* p  k$ j& B0 {
   return false;     ! e+ d! k4 V. a3 ~: @  Z5 x/ W
   }     2 V0 B! |1 O' E# n
  }
( a" ^9 t% l4 c9 [  chineseid = document.sform1.chineseid.value;     ( |7 g4 j9 d; @' v
if (chineseid == "")     
  W& e/ S# Z3 G* S' g/ c  {     
. D3 U4 g- f& R- S1 E6 j  alert("请输入中文昵称");     
! H4 K& l9 D5 m4 {( e  document.sform1.chineseid.focus();     
: D( e8 y4 H+ _) v  return false;     
) r0 R! c+ A2 W/ w  A! c7 \! `  }    # Y6 R  d# G. m9 L) W: D# H
password = document.sform1.password.value;     
7 f, R, m/ _! c9 Z if (password == "")     
7 _" r6 p, v3 Y  {     
/ k% b4 _. }5 D% n! `- e0 o  alert("请输入登陆密码");     $ w: D; s2 K) s0 T% P, E3 a
  document.sform1.password.focus();     
' g: r. z* H5 F8 o: c$ R" w  return false;     
: ]7 i. l; @: @7 p  } 8 m- ~  b' D0 G! k
password1 = document.sform1.password1.value;     
9 P% [- J+ W  d* ^8 S( P if (password>password1)     
1 I0 G) F4 P. O: U. t& n  {% z; r" \% x0 t  s9 j, r1 g
     alert("重复密码与登陆密码不相同");     + f+ l7 M" z- b4 r. N! T
  document.sform1.password.focus(); * _( b2 |; N6 R- ^
                                document.sform1.password1.focus();     
) S7 s! w2 x- D" V  return false;0 J6 G) f2 i4 J3 e' c& M9 f* O
  }  , h4 {  c. p8 S
if (password<password1)     
1 ?% F  K, X  [0 C1 r8 S+ l2 a  {" ~7 G9 ]" C6 r$ h0 p: C
     alert("重复密码与登陆密码不相同");     
, t% V. O; j$ Z; T8 M. p7 A3 r* E  document.sform1.password.focus();
" h" k; }/ X! P4 d                                document.sform1.password1.focus();     8 v$ Z, F' L2 E' z
  return false;
6 O* F3 x" _+ c* y/ D. C) E; b5 r  } * K+ s' q4 b( b* M6 a
if (document.sform1.email.value == "")     $ M4 m4 L- b" ^0 A7 d
  {     6 ^+ L- v! u1 P( \* d
  alert("请输入您的E-MAIL地址");     ) Q4 k. M0 K- V/ e% v: O. s/ y  A
  document.sform1.email.focus();     
4 z1 g& `. ?/ ]! ^" w" k! F! F  return false;     
$ i* ]  S! b! h6 ?$ j  }     # ^' b! \5 T; S2 s; F# t
      
* y1 v/ ?4 a! t+ u( V) W email=document.sform1.email.value;      
( L$ `3 c7 C# i- v+ B# K1 { emailerr=0     
' |" K6 K% s- {( d+ x$ y9 }; T for (i=0; i<email.length; i++)     % c9 P8 W. P- e. w% u+ n" T
  {     ' |$ L" d2 Y3 X
  if ((email.charAt(i) == "@") & (email.length > 5))     
8 A- G2 _- i+ m9 ?* ^6 N   {     & f) [% d+ _: D2 [* X
     emailerr=emailerr+1     
$ H/ P3 V% ^+ `+ U  @0 T   }     - H. e7 I) V! P
  }     
9 t  m- \% K7 c if (emailerr != 1)     
& I7 C% i8 S/ S7 W0 }) D, P  {     , @, L. @/ q" p- h/ Z
  alert("请输入正确的E-MAIL地址");     
, e+ K; \( B' j, |8 @; D2 V: j  document.sform1.email.focus();     8 O) W% l! H/ y0 a
  return false;     
" i3 F+ h4 d# I0 r$ r- n  }           4 H% q( l/ t4 R9 j
  / i3 w, w$ k7 z% b9 T
if (document.sform1.checkask.value=="") # ~9 P& Y8 h* M4 o, N: Z/ ^
  { + @" C; r; ^( L7 y3 [& Q4 N7 U
   alert("密码提示问题不能为空");     
4 ]6 N# W' g% e1 V+ d! G, f* O   document.sform1.checkask.focus();     
, f7 B9 G: d$ e7 P# t% @/ X   return false;  5 f, N) z7 s/ [" v+ q# d8 h5 u, w. e
  }
  h- _  I3 ~  e4 B6 K: `" M if (document.sform1.checkans.value=="") ' Y( i- b8 A  b
  { , C2 a: I; W4 D# E
   alert("您的密码提示问题答案不能为空");
6 S, u, Y* w3 d8 d! r6 |" X$ V! \   document.sform1.checkans.focus();     
* V4 U. E" f/ d& i4 p& n   return false;  
! }3 I( B2 _7 W2 S2 }8 R  }
& [; w- O5 n  c3 v* Q! p return true;     
6 |7 a+ n0 P  Y" L  b5 [     
# h' s$ W  ?! \. p- r& ^" G- m; w}
; }0 c0 V8 w0 K0 t1 f</script>

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