获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:! R; d, f! m6 `+ D) x
<script language="javascript">     
3 X- z! B$ w3 h% B0 x2 M7 Yfunction IsDigit(cCheck)     7 w/ e6 s# U; }4 h1 H+ Z
{     
# {+ r4 C! `: i, Y3 C& F return (('0'<=cCheck) && (cCheck<='9'));     
$ H6 V2 j* T" y }     7 d9 u! B/ p  e- d- [
     
. Q% t6 O/ V" f3 C) gfunction IsAlpha(cCheck)     3 V9 f& p% d- U* X
{     5 v  c1 A) N3 T4 p, E
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     9 c' w% W$ Z4 k1 @# K
}              
' B  C8 }2 y6 G, ^5 e/ D: O      
- W3 u. k, T5 o( S9 M2 xfunction IsaNull(cCheck)          * i- [6 Q0 r2 M' }! n) `% C
{         
: c  e% n; H% d; d* c return(cCheck != " ")         
/ a( R7 Q0 e: C7 ~% z0 O0 W }                               5 V9 J7 ~4 x6 E! q, q
      
4 x+ S+ Z6 J  E7 z: J9 Ofunction checkform()     
7 W6 w: M# J" c! C6 R; u& k{
7 X; ?* r$ I4 J; ]+ u/ W% @0 W) m/ E  id = document.sform1.id.value;     ' [4 e' B# {, d) D3 h& ^' G
if (id == "")     ; M( K5 R) j7 U* u& d- S
  {     1 l. z4 O' U7 ?& U2 P# h3 L) G+ i
  alert("请输入注册名");     1 p5 u* Y! E; ]7 k
  document.sform1.id.focus();     
' G7 z' c1 p6 d/ |1 w- P+ M  f  return false;     ' X1 A3 D) J. N7 f: L& `; O
  }     
; m: S: E( k% K- f6 J' c     
. o/ t% M2 G8 r! E2 D* I for (nIndex=0; nIndex<id.length; nIndex++)     
1 U3 Y. p! ?6 ]# }/ g9 @  {     ' L/ C9 R4 K# g4 L$ y" @
  cCheck = id.charAt(nIndex);     2 T* _5 A, C3 N( N
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
% ?4 U' ?; t3 u" A' E" a0 W   {     
. S3 C8 g2 a' f3 b& r/ S   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
; k7 u, O  u! y4 w7 F, B. C# [   document.sform1.id.focus();     
: a7 c: z" u4 f* A   return false;     
' k  m! i. l) ?7 k) s5 l   }     * ~* z6 L* U: ~3 h, U
  } / b2 _- L& O; d) i. r. X0 {6 Y+ x
  chineseid = document.sform1.chineseid.value;     
6 E# p& B4 G( B1 n, _" r$ u if (chineseid == "")     
3 \% ^0 ^7 J# V+ g  {     
7 f; a& Q6 e6 u. j& R0 M4 L/ F# I  alert("请输入中文昵称");     " Z. r- }3 Y9 c. Z( g1 j: J( t4 b
  document.sform1.chineseid.focus();     
/ e" [# Z- m* l; T# L" d& d( _  return false;     
9 @; ?/ r5 S$ `1 O& S. W  }      h' W7 m( P" x; _
password = document.sform1.password.value;     
6 A) M7 W- Y3 ~& i if (password == "")     
" r$ X1 C' u! m. k! m' n: E  {     ( Y* S5 F0 M+ T% {# E
  alert("请输入登陆密码");     
; N; \( A) R: \2 ^+ r  l  document.sform1.password.focus();     
! J% h+ p! u! ^  return false;     
3 Y1 \8 E% Q+ n7 q9 Y8 I  }
  M! U, p& l: ]  E# |# E  ^ password1 = document.sform1.password1.value;     5 }- }* P! C4 d6 m) [) b
if (password>password1)     
* W$ c0 x* S$ n0 y' i* }  {; S" t6 j$ c" u" d$ Z- c" z4 ^! l
     alert("重复密码与登陆密码不相同");     
: ~: q2 J, E8 O2 P  document.sform1.password.focus();
! I1 f' r# d8 h- P  H1 p7 H                                document.sform1.password1.focus();     1 ]3 b% W3 D$ a
  return false;" _3 C' v: |. E" V
  }  9 Z; B( S3 Y( O: R% d; X
if (password<password1)     
7 L7 J7 z% M( f, s  {
( @  F0 _/ v6 ^  L: M: w/ D$ B     alert("重复密码与登陆密码不相同");     + B8 Z% U. j, A) P" K! j( ?
  document.sform1.password.focus(); 1 o* a6 y$ F& V& _* @7 L
                                document.sform1.password1.focus();     : @+ C6 ?2 F+ u: `3 [3 F
  return false;
* L; G8 d' o: B- N, _  }
9 K& p1 I1 Q) e- \! R. G! D; {' g if (document.sform1.email.value == "")     + m  N; |) Q* u
  {     
  L. {( F' j2 q  alert("请输入您的E-MAIL地址");     
) x- n. `, Q) z$ G6 i2 T+ J  document.sform1.email.focus();     
3 l: [( ?5 T! K* ]  return false;     
$ C+ l; k! l- B  }     / _2 x( x0 O9 D  x5 {
      
! Y8 J# [- A; Z5 l& ? email=document.sform1.email.value;      
; X  L) J6 R$ l4 a emailerr=0     
3 [3 b9 F$ V# E2 l+ Z" F for (i=0; i<email.length; i++)     ( @7 c' A4 j, G+ p
  {     
' [# u8 z. E& [7 ^( L  if ((email.charAt(i) == "@") & (email.length > 5))     
: k4 N: @+ _! m4 P' [& X  ~   {     ( `9 Y2 v# ^3 S5 o" Q: q- {
     emailerr=emailerr+1     2 X, z: @; d" B, J( W
   }     
; l6 o: g, a0 ^) P" A' U8 a  }     
8 v+ g) K4 V9 q, w3 ^. G if (emailerr != 1)     1 I& ^4 W5 B# K. A, o" s4 {( _. a2 I
  {     
& G0 m4 V. j# _4 L2 v  alert("请输入正确的E-MAIL地址");     
" Y9 o* X% y0 b( y3 [  document.sform1.email.focus();       b5 H9 `" J1 ?# L! Y
  return false;     5 S. r$ F* Y% c0 u  g3 T+ Q
  }           
- j8 L1 H& n% G- S3 e! d' }' L3 i  3 N% b( m  [  i
if (document.sform1.checkask.value=="") - f  Y" t  J- y+ I3 L: a
  { % v9 N7 y: V# O8 |
   alert("密码提示问题不能为空");     
9 |/ Z7 a+ U: ~, B, I  n   document.sform1.checkask.focus();     
) o: F8 w, M0 p3 d+ {& X' s7 f   return false;  
- _9 M" G( I1 G9 s. j+ _; A, c  }
& |$ P; @1 b/ s# d# N$ F if (document.sform1.checkans.value=="") ' {! e; x. V% q8 S$ m5 S
  {
, t7 T2 ?( P1 _6 H8 c% z   alert("您的密码提示问题答案不能为空"); + Q5 b  W( G4 W0 Y% w, I( L; H
   document.sform1.checkans.focus();     7 ]- Y1 P+ a' p) k
   return false;  
: D; d% W+ C+ L/ t  }
1 E7 \, y8 |+ x" t% f  U+ \& b& h4 | return true;     / ~' |$ @; d3 C2 P' ]! b) Z. n. C
     ' v, `, `; a5 b' _& G
}
8 x% g: u, X0 z; t# S8 z! u</script>

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