返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
. R9 O4 |6 A: ^<script language="javascript">     & `1 n: {( u; F5 ^$ ^
function IsDigit(cCheck)     
) l8 j6 W, I  p* N& n( p! w {     
% Y/ L0 f: w( p return (('0'<=cCheck) && (cCheck<='9'));     
' w/ _, |6 W/ [2 D6 f2 p" E7 o& j }     
2 N, }' ?8 h" Z8 p0 s: {* U, P+ M     3 V9 m  v+ }5 M0 @8 C/ K7 I
function IsAlpha(cCheck)     + G+ }& p. Q3 E+ H1 K8 h& q
{     
3 x6 W* m7 _. H8 b9 T5 q* _( Y3 ? return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
9 j) w" ^% l7 {8 l! M }              $ b* T/ R- N5 W) _5 ^2 j/ {% ]
      
3 L( W6 L; n1 l$ F& m% ^$ ^% |function IsaNull(cCheck)          , a# z0 o4 q) ^2 [. L
{         
9 b. M$ e2 R# B2 o* N8 C0 K* m6 X- V return(cCheck != " ")         
- N. J. j. o; Z9 Y! { }                              
5 _( _; ~3 r7 Y# I! X0 U      
8 ^9 A' g# O3 m( C5 Z6 gfunction checkform()     
+ n8 f7 U0 B* D) T{
4 u0 y' @+ |' S. {  id = document.sform1.id.value;     5 _7 d  M" Q& ^) E
if (id == "")     
- W/ V/ w6 h/ \. O  {     
# ^5 Q7 C5 [! w  alert("请输入注册名");     3 U7 d' U' d3 [+ \
  document.sform1.id.focus();       f0 u5 F! P) ]( F
  return false;     . {; t* R8 |/ J5 ?% M
  }     6 c5 ?+ u  H0 d% u- F
     1 E" Z  B( \% ~8 v5 {5 ~4 @) R
for (nIndex=0; nIndex<id.length; nIndex++)     
) U$ K( e+ M. @+ c0 q# w( o" e  {     : _* p6 U3 X: k9 Y4 I0 e
  cCheck = id.charAt(nIndex);     
4 F# C  m& k  l! X5 V  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
7 B* r5 `9 I1 y4 S2 L   {     
2 e0 Q8 U+ v5 p& A   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     / k& K- _& Z, b4 `- M4 G' }) l( p
   document.sform1.id.focus();     1 ?  z# M8 i& K, g4 ?
   return false;     , z9 p: P2 Z; A5 h6 X
   }     
7 w, \8 l& u) a  } . b- B- k3 H5 T5 k5 P/ I: z
  chineseid = document.sform1.chineseid.value;     7 A& S1 D) x/ m) h! K5 w1 p3 p
if (chineseid == "")     
' t0 K- z# W) q' Q$ @  {     # {4 \2 @3 R4 }- {
  alert("请输入中文昵称");     9 }0 j" C9 K5 L; Z3 i
  document.sform1.chineseid.focus();     1 {) n5 a( [; g- p8 t. }- f
  return false;     , D% _  H# o6 [: b5 N( o) l9 q
  }    , I( z# t, Y, d- r( l5 F% S
password = document.sform1.password.value;     4 O% N9 Y2 v2 n; J( a3 i0 S
if (password == "")     ' z" b# x$ b, y+ N) W7 f- ?( ~; p2 G
  {     & Y! n7 r+ t! B  s
  alert("请输入登陆密码");     . H3 G! m% [6 a) ^  F
  document.sform1.password.focus();     & _6 Y. B, f2 r
  return false;     
& `3 N9 |* ?! A9 h8 k& B' A  } ( g# @$ d, M7 I/ E( k6 q4 X9 t
password1 = document.sform1.password1.value;     
+ Z7 P2 L5 R- Z. K if (password>password1)     ( O# ~& K: x5 I4 o8 E$ _
  {- h0 M# f4 G. t- [, V  K
     alert("重复密码与登陆密码不相同");     7 O; Q) Y, {' j1 c1 l1 R5 k: z
  document.sform1.password.focus();
' F7 \3 o  X: ^                                document.sform1.password1.focus();     
, q5 o5 k6 [  _1 u; Q  return false;" g$ ]! y6 o7 ?/ W3 b
  }  
+ z" l2 I* h0 F% D+ S, h) c; f$ Bif (password<password1)     
5 `6 [4 Q* u7 P- u7 Z  {
. y; @) N  r5 @     alert("重复密码与登陆密码不相同");     9 W; G. t; V! O
  document.sform1.password.focus(); # ~+ Y+ A. `# G: G. Z" v. U
                                document.sform1.password1.focus();     
( t( J& w( E$ a& v  return false;( {6 I* {) [# G- o0 d, x  A& g, B0 k
  }
+ X+ U# A$ d9 [! C if (document.sform1.email.value == "")     $ D: L, P% D  u0 p$ F4 F
  {     
$ N8 Z% I" b5 V; C. y1 l  alert("请输入您的E-MAIL地址");       I! w/ Y: E6 X. J( C' {
  document.sform1.email.focus();     1 [& }$ J- M, @# J* S1 ~* Z
  return false;     - }3 C* p; X+ Y6 `
  }     
' ?! [: ?. B. G% Q4 ^% d/ T* E9 |+ C      6 T; E! ]1 x1 ~  f+ s+ q
email=document.sform1.email.value;      $ M2 Z! U+ R1 {; k
emailerr=0     
* d: v& P( F% v% f for (i=0; i<email.length; i++)       j& ^% D; x. m) E5 V# Q) W
  {     & V! v3 {- A8 `3 O5 S# V! G
  if ((email.charAt(i) == "@") & (email.length > 5))     
4 q8 x: U# P* \! E$ U   {     & F( B5 ^. r, \, k) H) f& O8 Q1 F
     emailerr=emailerr+1     & D, R+ k  K+ v' X- }
   }     
$ O$ }6 Q6 a: Q$ j* r. j  }     
0 m* n2 H' [8 y" O  B" M if (emailerr != 1)     
" Q; m" z9 l/ `8 S: O0 g  {     
1 L2 |" V% Y& C8 e  alert("请输入正确的E-MAIL地址");     
" Z* M! l1 F+ v3 X& a- h  document.sform1.email.focus();     & g7 |4 P' q7 z) D+ k" k
  return false;     
0 \. d. S7 y3 }+ j6 O" l; K2 }  }           
  E9 y% `( j" ~  # {( s& W- `* V
if (document.sform1.checkask.value=="") ) M* Q0 d3 I* ?0 q3 t
  {
9 P% u( Z( r) U( V: B   alert("密码提示问题不能为空");     
0 [9 A) P5 R: d" T2 }5 u   document.sform1.checkask.focus();     # h, `0 `2 }2 i+ I. A- S
   return false;  + z2 n/ w* o2 n9 m# w7 }
  }
! e# M" N  C( V6 |2 ~, g( { if (document.sform1.checkans.value=="")
, X+ N/ X8 J7 J2 M  {
7 E2 y' D- c5 i5 T( O   alert("您的密码提示问题答案不能为空");
8 r0 E; y( d# P3 I+ ?2 R   document.sform1.checkans.focus();     . U6 l! D- u  }( [4 {
   return false;  
# j5 X3 l1 j: S0 {  }  X) p3 v, \# `5 C. f' m7 I# f. R
return true;     
4 L+ I2 S7 X5 J/ ^( H: C8 [     
5 ~' v  A" Q( t8 t  X7 v' o9 I} 1 b# X) e5 e, z  N2 ~, ]
</script>

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