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

一个注册表单验证的js

这个脚本对你可能有帮助:+ d/ y( H! J5 S7 h
<script language="javascript">     * U* f1 X( [" _7 `$ S6 r/ k( |6 ]+ ?
function IsDigit(cCheck)     3 R' t3 b5 Q) U2 @
{     
, A# z9 O8 M0 p5 D) m. f return (('0'<=cCheck) && (cCheck<='9'));     ) M. s0 |  @# x" q( D" c
}     
0 G1 U+ O* x8 s* ~     
" }5 l8 r8 D' h6 k; Bfunction IsAlpha(cCheck)     / N8 l" v3 b1 v" X, b! d0 ?
{     ; \# T5 A6 t' l9 K, d, \
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     2 K8 `. t' c& y  i: _
}              
6 N* Y- R. U; I% n# Q      
  K2 J7 z; T8 vfunction IsaNull(cCheck)          / I- z* v$ E) \) v" Y
{          9 n7 n0 {- I" V+ K
return(cCheck != " ")         2 E* G* B6 M- T9 r, p
}                              
: X6 G' S7 g0 Y0 Z9 ^      ! h. M% a4 ^' G8 v& {
function checkform()     
& s5 P) J- e+ ?$ q% B{
7 F: }! p9 s5 D3 a+ c" I% V) n  id = document.sform1.id.value;     2 ~$ A) k( ^5 p7 B) F
if (id == "")     ' o- B/ i- J9 F# N5 ~
  {     
( n, A* J2 r% s) I- M. N$ O1 X  alert("请输入注册名");     
- E3 b  J/ i$ W$ o  _  document.sform1.id.focus();     9 S$ ~$ A$ H2 q4 G  g; R# a
  return false;     - t+ h9 p% ], h5 M3 q; ]
  }     
# i3 \' w3 p+ R     
2 ^9 x0 b# f- S for (nIndex=0; nIndex<id.length; nIndex++)     
- Y. l3 s6 k5 u0 u1 M) J8 W  {     & Y3 J0 |& ]8 m6 ^" `# g
  cCheck = id.charAt(nIndex);     - X1 O$ j+ s9 ?& I2 }: @
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ) W( T' G  ]% i% _1 P3 S* N! n
   {     / \  p+ b' @% @  ]4 o  U8 d
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
6 _7 P' y' s6 ?4 n- T4 g+ k, t   document.sform1.id.focus();     6 b) J  _" h, V( E  P' `1 F6 y
   return false;     : a# U& Z: e: i! E6 V! E
   }     7 T' a7 m0 |- ^# d9 f! s
  }
4 B/ h+ k7 r/ H1 ]  chineseid = document.sform1.chineseid.value;     & }9 l# @3 P0 n" b% i0 p( n& K
if (chineseid == "")     8 v% V8 E& n) g+ Q7 ~2 E! \
  {     & o4 n3 x2 b" x
  alert("请输入中文昵称");     
0 Z% Q2 u! z$ v: M. f  document.sform1.chineseid.focus();     
) Q  u7 b* ?" j, H0 S2 N$ g8 x  return false;     % n! I) z( G2 I" |
  }   
* k0 s8 ]) ]8 h6 ~: x password = document.sform1.password.value;     
2 S; c* `2 V5 m if (password == "")     
3 l( A( y4 K7 g& U  {     
; k" U/ j. F0 z! }  alert("请输入登陆密码");     . I9 F" A2 w9 _+ K9 \
  document.sform1.password.focus();     1 Q& u2 l" n; E8 Z+ \* W  ?
  return false;     
+ ~& G( l8 V+ q) C$ ~( k% _  } / \2 l  f5 C' ~1 f
password1 = document.sform1.password1.value;     
0 [) T1 r- y$ a) K6 N& w. S if (password>password1)     ! ^# \2 }5 R2 l
  {4 c9 V" l2 r: u
     alert("重复密码与登陆密码不相同");     * d& L& R! D6 U3 ?& v$ g, ^. U
  document.sform1.password.focus(); ; F: W. j4 j6 [0 p
                                document.sform1.password1.focus();     
! u' }6 D0 W3 N5 s  return false;
4 e4 H" |" m/ T  ~8 X  }  
: N' {5 h; C( y8 Rif (password<password1)     
2 l% I& C/ N$ K- n/ f) V  c% W% \+ s  {
3 Z' Z6 b8 q* K; f+ F$ w     alert("重复密码与登陆密码不相同");     " G- w/ |7 k6 V2 \5 k
  document.sform1.password.focus();
) W+ r/ I6 k1 d: B5 x                                document.sform1.password1.focus();     $ F; t; L8 @0 C( x
  return false;
8 U+ `: C* L0 `" V+ X  k8 N  }
8 j- w" P7 e  B- d if (document.sform1.email.value == "")     
0 d: {5 Y9 K+ U  {     
& t) p0 M. x0 @  alert("请输入您的E-MAIL地址");     ; S$ P8 L/ U5 l* q0 C$ S
  document.sform1.email.focus();     
5 F+ c6 X( W, F+ \0 ~8 ^8 Q! O% w( ]  return false;     / e/ H, b- I  Q, D
  }     
- Z0 H# O  }4 W; B0 x9 N% I      
' |# a6 J& L$ A  Q9 y$ w email=document.sform1.email.value;      
1 T8 N7 R9 M  u# Y emailerr=0     
. Q( A; u" ?8 }3 G: Q! d for (i=0; i<email.length; i++)     
" r3 J% p1 A$ x( d% V# r/ C  {  {     4 P! H* j5 V4 E5 q. v" m
  if ((email.charAt(i) == "@") & (email.length > 5))     
  s4 T  o- g' e, h/ q0 f   {     
7 E4 S3 R' ]  m$ B' y0 _2 r7 i     emailerr=emailerr+1     
9 o5 `/ _9 h8 b2 f: N( o   }     - l: g3 _4 C* J8 u
  }     
) R" H* n: i* S# B" O if (emailerr != 1)     3 \6 _/ \0 i9 q# P' i
  {       m4 [& e7 p/ Z: _8 q; j5 R$ h
  alert("请输入正确的E-MAIL地址");     
, W  _# u& w. K( `& y  document.sform1.email.focus();     
& p( E' }$ S5 L- q  return false;     
* q, G- @, J% _8 n9 ^  }           
) _$ l+ U8 _# q  \  ( b* R$ a9 i8 T7 D
if (document.sform1.checkask.value=="") 5 ^+ C1 u9 X% B7 i+ a7 H! H( s8 R! f7 ~
  {
$ r1 S3 A9 D# `" s   alert("密码提示问题不能为空");     
' p4 W$ a( A: p2 N- {9 B   document.sform1.checkask.focus();     
2 f* Z# j9 i% s   return false;  ; W2 [6 [7 ^1 B' y! q
  } ( G0 ?) \- F) J: C
if (document.sform1.checkans.value=="") 3 x0 X; k5 {$ s+ J
  {
, `4 T& `1 @; B% _   alert("您的密码提示问题答案不能为空");
) M% u) S1 v4 Q+ W, L) Y   document.sform1.checkans.focus();     4 u4 `2 }6 a; N
   return false;  
5 l( W+ Q9 f9 d2 {0 i: d5 Q  }! }1 j5 O5 f7 o" Q% u8 H! L
return true;     1 j: ~5 U. k5 m% V2 y  R( `3 b$ f
     / L- s" ^5 H$ U( a8 g( C4 @' i
}
5 x+ p* `) h6 X  u$ o! T</script>

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