返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
/ @7 S* P1 p0 V2 k5 Q6 O7 s/ h<script language="javascript">     ! y% z9 D( f: _+ w* g  g
function IsDigit(cCheck)     + b* z* P5 G4 D! R$ X6 X3 `
{     4 N8 A0 x  F* O, L9 Y0 _* R
return (('0'<=cCheck) && (cCheck<='9'));     8 }4 H* A" e# U( z; i8 R
}     0 L9 z; M, Y! _! O
     . `. l9 u5 B: B3 q3 V
function IsAlpha(cCheck)     , X2 H$ h8 k$ }7 D0 ~/ \8 w- }
{     9 W" O8 I" j8 z. A4 k! _- s% H3 V$ w
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     9 ^3 E! _) F; A, m/ c+ G) y5 C4 g& `- t
}              : j5 ]( d) x( B3 r8 {- h
      3 p  q& w5 Y2 B% p2 r9 g4 y
function IsaNull(cCheck)          " d  J) S. @$ m) J% s; j7 Y/ V
{         
+ m8 C$ s! K. A/ g2 e, W# f return(cCheck != " ")         
8 H+ M9 F3 v# D, l }                              
4 e: y* t, {- Z  I      
, k# U8 G$ }, t8 Q1 efunction checkform()     # E2 j4 }; P" O' T) Z5 H9 g
{
" A1 J7 U' ^% t2 W! A4 d1 @  id = document.sform1.id.value;     ! l6 W/ J# c6 [( H9 O- x* M
if (id == "")     1 u# i  u, u9 K2 Y# l1 L
  {     
' T8 e- k: z4 R. K, }2 p  alert("请输入注册名");     
. x0 t2 y: ^& o  document.sform1.id.focus();     
9 q: W  C/ `& i* L# e! g  return false;     9 d( _2 A# n( y; s  x7 c, u/ N
  }     2 ~0 L& m2 D5 r  [: ?1 U# z# W, L
     ' ?3 u' i! x0 O. g6 h+ E# N
for (nIndex=0; nIndex<id.length; nIndex++)     5 @) a* \* Q, b: Y* Q
  {     
( }. D9 ?! s+ a8 m. R1 ]. D( ]  cCheck = id.charAt(nIndex);     
/ a; _& ^+ A9 v  S4 a8 w/ ~+ c4 V  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
6 x! v/ v' r1 ^/ \   {     7 s6 l3 A; U8 w3 ~' B1 q
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
# b+ Z* j/ `0 v, m! A( i   document.sform1.id.focus();     * ?1 U& W' S" h- ?' X
   return false;     
* Q" ]& D. ~; I" e   }     + s: l9 F9 ?& P* a8 ]
  } 4 W5 o: Z% f) ]$ b! ]1 e
  chineseid = document.sform1.chineseid.value;       C% X4 T8 ?5 S5 `9 d
if (chineseid == "")     . z* y* \4 c0 Y5 I
  {     
# o* I( ?$ ?4 j( i& ^  @# P. ]  alert("请输入中文昵称");     
9 U  X* y( K/ N3 n" X1 n2 O" d* _& l  document.sform1.chineseid.focus();     
' }3 ]; Y; G) d( o( W1 ?; s! v* F$ e  return false;     
; J: i  v1 A4 ^- q% H( Y5 Y+ u& }8 z  }    5 h) n' d5 N7 h9 q- B. L
password = document.sform1.password.value;     - [+ u$ H! y! Q6 J1 j$ [
if (password == "")     1 W# H6 T3 a- w5 @, p) t. A: K
  {     
& S( ^% z  w8 r& c  alert("请输入登陆密码");     / B9 X3 d; Q  K- ~7 m( B! R
  document.sform1.password.focus();     , x4 }" _3 ^0 O4 c% i; _/ x
  return false;     9 d- M2 |( \& T  l5 s
  } ! [4 b( r' Y+ R: y5 M( O4 u
password1 = document.sform1.password1.value;     
3 C* [# Y1 u, d& \. n+ t9 _ if (password>password1)     ! N; ?( X1 h' E3 e
  {
$ V! Q$ S* N5 P* Q. v' W: H     alert("重复密码与登陆密码不相同");     
8 |8 }6 b/ D8 i% n# _6 \7 k4 o2 X- C  document.sform1.password.focus();
2 Q5 j7 @3 Z; w5 W: b                                document.sform1.password1.focus();     % j6 K; v, I6 L/ \3 D- ~, x1 a
  return false;
6 \; l' u' G  \& E3 g( S  }  $ P4 K. Z) B, a2 m" q4 a* B
if (password<password1)     . C# C. |1 f+ ^( }3 e
  {6 y; m% @) n  a- Z/ Y' g5 `# c% ]
     alert("重复密码与登陆密码不相同");     / v- P9 z3 t& }, {3 l9 O
  document.sform1.password.focus(); . U' g; i( `3 M/ s; i
                                document.sform1.password1.focus();     6 _  t% {% y( r0 f3 R
  return false;1 d4 L  `" x' g1 l
  } 4 Q8 p! m8 G$ e3 k$ n" B
if (document.sform1.email.value == "")     * A2 P+ I/ l( b. G% k' M# O
  {     3 n+ c# Q: t2 a7 [
  alert("请输入您的E-MAIL地址");     % F* z7 K/ _  e) f# ]
  document.sform1.email.focus();     . h. Y1 L4 ~8 w$ i, ]. V* z9 D% E
  return false;     6 J( b0 T4 m( F5 a0 A
  }     . ~3 C+ h- {3 T; `
      
, ?% c7 U% F' {% U: r- b/ O* a email=document.sform1.email.value;      
0 w9 u" Z+ U# m* Y: p- u1 n1 } emailerr=0     . U: g* \$ ?2 H# B) D9 w
for (i=0; i<email.length; i++)       r  f2 m: E2 N: ]1 j0 f$ W
  {     
( X! o# W8 A* G& I( q+ F2 t  if ((email.charAt(i) == "@") & (email.length > 5))     ( j+ i8 l! n- x
   {     
9 s: N2 m" O5 ~2 K; p1 u# e     emailerr=emailerr+1       D0 o9 t1 H/ q9 G! y
   }     2 H2 P1 p- t2 C+ i) }8 Y; K
  }     
# ~0 O7 Y: z, C3 N. m( C1 L1 { if (emailerr != 1)     " \( d  s- m. b/ }
  {     3 ]5 O( A/ a  x
  alert("请输入正确的E-MAIL地址");     
* ?$ ~  W0 |" E  I+ W) X9 _4 Z6 U  document.sform1.email.focus();     
2 f( i; W0 J- L/ o+ Q6 _* f  return false;     ' g- F. y- Q- l2 [2 y
  }           4 |' D9 l' x% `1 b# W/ X, D
  
! |# q5 U$ P' O4 }. r if (document.sform1.checkask.value=="")
2 H* S0 l+ `6 G+ p/ K' N7 ~  { , o( e4 C6 o! Z4 ]$ f: O
   alert("密码提示问题不能为空");     
% X, R- m7 Z8 g! O( U1 Z   document.sform1.checkask.focus();     
" D. V; w9 }# _  Z0 x   return false;  
' T$ y; V; Y, [5 G  W2 Y, F  }
6 ]  j# ]0 d/ q, I. g. E2 z8 W if (document.sform1.checkans.value=="") 1 w- I! w) }  {: t
  {
3 Z* L7 c2 _  D   alert("您的密码提示问题答案不能为空"); ( o; s/ ~; f8 ?4 e( u( F
   document.sform1.checkans.focus();     
4 r& i+ j: d7 V   return false;  
. [) V& g5 E  h7 r& }" ~  }+ Z4 @. d) |; g) s$ t4 N
return true;     ( U* [( f4 s7 a! E2 K' w1 i
     
3 l! A8 [! z0 [}
; F, [: K* G( d8 X5 O% Z* |</script>

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