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

一个注册表单验证的js

这个脚本对你可能有帮助:8 n8 L& s0 v# _
<script language="javascript">     
1 O! p- S0 v$ x' j" L+ O, o! Mfunction IsDigit(cCheck)     / Q5 E/ e: y. f$ X
{     3 A  P, E5 C3 u, v1 c5 d3 m. j7 O
return (('0'<=cCheck) && (cCheck<='9'));     $ V9 U+ I" L( g2 E" y
}     : p# U$ a$ R, ?5 j
     
2 T* Q$ P( W8 B* zfunction IsAlpha(cCheck)     6 Q! M' K  j3 s1 H
{     
4 v* C' M8 Q  ~0 `# \ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
1 L/ s* S% o" ]! w* W6 r }              
$ k+ k) B9 h- P/ O- N      5 ^3 t: d- X% o' W: g. S6 Z7 R
function IsaNull(cCheck)          8 L! @! r8 F0 n( u8 d" J
{          1 K: f: K  ]( Z0 a$ d( k
return(cCheck != " ")         6 ]$ @" ]4 F+ `5 A; j& w! c" Y
}                               # U# K' M: x5 I# i
      
( h7 P6 N9 S; i) Sfunction checkform()     
* h) g- Q* i% H" n: j: V; y, L{
9 z0 R8 G2 z3 O- F+ e  id = document.sform1.id.value;     ; a% B! R. m8 |# M4 `; |5 {
if (id == "")     
7 A/ v. M% S, X; P! A/ X  {     
! T& ^6 ?& {8 [# y, g0 r2 s  alert("请输入注册名");     
" b& `, C8 P' m8 x3 n3 _- G' q  document.sform1.id.focus();     
/ w2 n" J' U' b: l( o  return false;     
+ j4 H7 z3 V5 F  }     - t1 G/ ?# K$ q) o0 y5 Z4 x7 B
     
$ o# D+ L: J4 n8 ~* n. V, T+ U for (nIndex=0; nIndex<id.length; nIndex++)     & k' B. S4 E0 X" ?
  {     
) v5 `! M( z% {+ o  c) F5 F# b  cCheck = id.charAt(nIndex);     
2 f+ s( J( t7 J9 N2 ~1 v  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     4 `! g9 S9 h7 s* Z$ P; g
   {     
! f) T0 W& ~2 n* d7 G1 _   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
" ?+ V! M" k% j+ \: Q4 c   document.sform1.id.focus();     
+ \8 E7 g. b% f5 L) W+ e   return false;     
6 t4 N' C' e- B9 Z" U* v% i/ @' F   }     7 x5 n2 d7 z, G- S% @$ s) O
  }   E2 z& Z+ e4 q6 M) D" f
  chineseid = document.sform1.chineseid.value;     
, U, o9 x  P: [" ?7 C if (chineseid == "")       T+ I8 t# m& O
  {     
0 L& G4 |7 ^0 U6 Q6 S+ U9 {  alert("请输入中文昵称");     
6 L$ m" t% K6 T, q; J8 L5 C# V6 _  document.sform1.chineseid.focus();     
6 C( [; r" l5 q  D  return false;     ! C. ?% j& G: h! y- {! z6 L
  }    ' I8 F1 i6 u  b% l
password = document.sform1.password.value;     7 e9 Y+ I+ V4 c+ y) Z/ p( a8 x' @
if (password == "")     ! i$ a9 H& A* _9 Z. Z
  {     ! Y- M/ B# g7 Y$ M
  alert("请输入登陆密码");     
$ r0 s! ]5 ]' ~! b; H! y1 o+ |  document.sform1.password.focus();     . s$ C, y1 A! |: U7 V1 n
  return false;     
& [/ o3 D" ^! Q& F  }
; h- H" |' f( ] password1 = document.sform1.password1.value;     , C, R; V  E2 e  h0 n9 f
if (password>password1)     
! B4 D9 A1 O; k: l4 Q8 o1 x2 X. u0 x  {* V' V5 I4 B, f/ ?* w8 n# W
     alert("重复密码与登陆密码不相同");     
: e0 p2 w+ d$ V7 T  document.sform1.password.focus(); 1 }6 L; h& V. ?& R% _
                                document.sform1.password1.focus();     
! _  N& U7 P7 `. i0 t  return false;
% Z4 I- Q: g+ E# h' c4 `4 y" m2 J3 }/ j  }  1 T- n- V1 l1 h
if (password<password1)     
$ e8 Q* T6 c: o5 x3 G  {& M$ s  d; h9 N' V7 {  H' M% m
     alert("重复密码与登陆密码不相同");     % A: z& `& m9 [% T9 P; ~* g6 Y9 m  E
  document.sform1.password.focus(); ! u6 l5 o4 ^# \0 {
                                document.sform1.password1.focus();     
7 ]4 u# _5 g3 N$ F( z9 _( f8 K  return false;2 w) g' f8 z" t4 p4 f) a6 Y' B
  } % i) v' \) X& X) L) p7 ^
if (document.sform1.email.value == "")     ; P0 ]( {7 L; }) d# P4 o
  {     
4 k; Y* D; J2 b. S- E  alert("请输入您的E-MAIL地址");     # |0 v  a  Z* D7 k% H+ l9 l
  document.sform1.email.focus();     ! A1 w: W6 M  S) U  L
  return false;     
& T. H, o# E) W/ E$ t3 a  }     
& x% p* Z/ Y( A/ c      ! a! h! d: V0 M2 l
email=document.sform1.email.value;      : z$ I- i  Z" n2 F; f
emailerr=0     3 _  N/ N  A' h0 x
for (i=0; i<email.length; i++)     
  E8 y; \% m8 x+ \! j  {     - R8 ]/ j' j. ]2 X3 C
  if ((email.charAt(i) == "@") & (email.length > 5))     ! H* ]* v0 c- _, y2 H! b
   {     / e/ F+ [3 {8 x: ~& G2 b1 w
     emailerr=emailerr+1     0 {' r1 z  x' U# P  w; a
   }     / B: E2 b% q; w( b$ l2 I
  }     
. t8 i6 \2 t: n! i, \/ Q7 t if (emailerr != 1)     2 G( a# p2 X; t
  {     
0 P" ]" F$ i" I, M  alert("请输入正确的E-MAIL地址");     5 ]7 V) z) S. |  J: N, V
  document.sform1.email.focus();     
  ]- t2 R1 z7 }9 a9 U+ V  return false;     
. j- y: @: _6 u4 Q5 j' |7 X  }           - ~& l( G. w: B( ]
  
, p+ n3 p6 }* \& o9 J if (document.sform1.checkask.value=="") " I( L6 Z/ i  I+ S5 J* T
  { $ P7 J& O/ @8 S, \
   alert("密码提示问题不能为空");     
' z: g0 O- R2 j. y" o" d0 M8 H   document.sform1.checkask.focus();     ) L% d0 X/ _  `5 [* d  w$ ~
   return false;  + o0 c8 p5 x2 |1 l
  }
( }4 Z- P7 l2 [2 X/ ~9 P! J. a/ P if (document.sform1.checkans.value=="") 9 w" C; z. f& \# p& }- ^
  {
9 Y( F/ I) A4 f/ Q+ X7 R   alert("您的密码提示问题答案不能为空");
: [# Q' E) |" q1 z  b* ^   document.sform1.checkans.focus();     + ^. f5 t$ b# |+ j( E
   return false;  
! X7 ?6 H9 ]) I4 X6 N  _9 L  }
* j" a1 @4 Y( s- m- `/ ]; } return true;     
+ Z0 F) @2 d3 \     - g* Y3 r* F8 x' S5 h
} 7 B8 ?5 p6 k1 Q$ m, ~- [$ X
</script>

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