返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:6 q  `! c0 h+ J- W7 V+ u7 K- y4 H
<script language="javascript">     $ X6 h- V6 [0 e
function IsDigit(cCheck)     
+ J/ \% C; z$ T {     - F' L+ J9 Z/ d  A# X# k
return (('0'<=cCheck) && (cCheck<='9'));     2 }9 |& g$ C0 m1 [4 B
}     0 A0 n/ V# D7 Q" V9 M* f* K2 h
     
- I5 W; S4 S: s; Hfunction IsAlpha(cCheck)     * v  S6 m. m6 W% ^
{     
4 K6 \/ ~4 s* }, j7 K! }4 A: n return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     9 Y+ D: C1 W8 h1 i9 j1 e
}              ( j. `, ^0 U. f) Q0 M
      8 k3 \. [' `! T* N/ B0 k
function IsaNull(cCheck)          4 }7 d- s% i$ U2 g( B- U
{          + h$ B$ }. S$ R$ \7 V7 F0 f: S
return(cCheck != " ")         
/ C# \1 e8 k* x! d( w& n }                              
. v+ k; w  Q* e+ z# I0 x% a      
' q4 {% M5 s6 B: f4 x: k6 L5 t3 nfunction checkform()     
4 T+ A2 B. n& h* O{
" u7 P# i9 w6 @0 e  id = document.sform1.id.value;     
9 V: l6 z: [4 {& e4 l! @3 h if (id == "")     
/ [  B# N1 m* J  Z7 B- [* D3 K  {     / N7 n4 y# s+ K8 O* ?3 l. c5 x
  alert("请输入注册名");     . O$ p- t5 j% \! L
  document.sform1.id.focus();     
$ X' F% y% D. G+ j4 q; _  return false;     ( S( t% V! \2 L3 ?7 {' f7 N& I
  }     
- z! b8 E* I$ [! `" E8 x+ ?  U     
8 p! _% }0 P3 ~+ ?: s& V; ^ for (nIndex=0; nIndex<id.length; nIndex++)     * c! ~; N( m) Q* S4 J
  {     & |; C. m  E3 R
  cCheck = id.charAt(nIndex);     1 ]& `6 r* S8 T( D6 T
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ) P8 B5 b$ k5 U$ b7 a
   {     6 `0 b" I( u5 A/ {1 @
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
2 A* S! G! q( L+ z! h+ X4 ~6 A$ `1 f, c   document.sform1.id.focus();     
+ r1 X" |/ Y% `/ {- S8 e! D7 w2 m; q   return false;     
) _5 I' Q  T3 u  g; o2 ?   }     + S5 O0 N; h. U. {
  } ) G9 |6 ^0 b. P3 W9 D) [
  chineseid = document.sform1.chineseid.value;     
6 e. \) x) N' }' ~7 ^; ?/ H+ m3 @2 d if (chineseid == "")     . G2 ~, e+ c- n. c0 R
  {     - B( w6 z: o# \; T
  alert("请输入中文昵称");     
. y: z2 \" L, s  d4 ^; Y: v  document.sform1.chineseid.focus();     
' G% Z+ u0 o! `" q% g! z  return false;     
+ ^- ^% a& k- Q& _, h8 o  }    ; S# ~$ m1 [! [5 w3 o. w
password = document.sform1.password.value;     
8 L* J' L  M7 T3 x- T* a+ X4 l if (password == "")     
- h2 x; T* ^8 ~9 |5 z  {     
4 ~# Y9 ?1 q9 `% [6 N0 [  alert("请输入登陆密码");     $ k( C. n" J6 w6 S% u) y
  document.sform1.password.focus();     3 q- A2 j3 {+ J' Q# M: S0 J
  return false;     3 M' v9 w1 l5 i6 o
  } 2 R: }' |5 p: V; b
password1 = document.sform1.password1.value;     ( ~3 m5 j2 ~) A. t
if (password>password1)     1 L* V, g* s: {3 v
  {" U  w- D: B6 G  m% n7 i
     alert("重复密码与登陆密码不相同");     . E6 F/ d0 ]- V+ K1 x
  document.sform1.password.focus(); 5 O; Q4 M- t4 b( _# H) Y- G: Y
                                document.sform1.password1.focus();     
2 j$ ]) P, t( L  return false;$ z; ~( \+ P$ ~
  }  
0 q* `5 v: U; f4 f( I& j$ t9 Zif (password<password1)     4 M% D0 @0 {# c- }. K; M+ q; q
  {7 C/ p% j1 O: }5 _
     alert("重复密码与登陆密码不相同");     
4 A: n1 q7 ]. h& I  I2 j& }3 Z  document.sform1.password.focus(); $ |. `4 t8 R7 {
                                document.sform1.password1.focus();     
8 T! C) ^( g8 {& T% n: f( h  return false;
( u* w/ Y( x3 m5 ^3 J0 x  } * _8 t; x1 A0 n6 y* O6 d- L+ G
if (document.sform1.email.value == "")     
  |: v( ~! T/ B) A  {     5 h1 W, Q0 Q8 H) F7 q/ Q( Q- t
  alert("请输入您的E-MAIL地址");     
" J8 ~, N* o# |4 ~$ n, e! f- ]  document.sform1.email.focus();     & O) `& h5 e6 [$ U, V
  return false;     0 s! _1 }, ~# h6 L$ Y9 @
  }     
0 G; j$ j/ S2 j( K* I      
4 Q5 d* U% Q  |+ q8 B, y& H email=document.sform1.email.value;      
( I3 z, t& V0 b+ Q9 f& ^ emailerr=0     % g% L5 b0 ^+ H7 {
for (i=0; i<email.length; i++)     
7 c( U. n& r( F; s; P. _* B  {     % W, N8 d+ ?/ [+ T
  if ((email.charAt(i) == "@") & (email.length > 5))     - J, `5 ~! n; R
   {     
0 \5 X& `, J. X2 _     emailerr=emailerr+1     
( x8 E& W' w' G   }     * Z0 K+ L$ e& A$ N/ b0 s
  }     ' D/ ?0 b9 G6 |, H/ A6 G
if (emailerr != 1)     $ E7 k: M- O. F% j
  {     
, Z# i3 _; U+ s3 e, N  alert("请输入正确的E-MAIL地址");     : S! Z  X& N7 i9 ~+ T8 B
  document.sform1.email.focus();     " W, k7 P: N% k1 W
  return false;     6 `$ M2 @* Q. N- o& Y& X# z
  }           4 F5 J3 h) Y: ~$ Y7 d" p9 j4 o
  
. i5 l% ^2 l8 J5 s, g if (document.sform1.checkask.value=="") % W: P9 M. {: }$ h+ L3 W- }3 V. z
  { # t, c8 S/ ^; {. s4 z1 g1 T
   alert("密码提示问题不能为空");     
* T% j( n8 W" r6 g   document.sform1.checkask.focus();     
1 f$ h# Q+ x, d' X! l  w7 w   return false;  % O# R, Y, I8 O( }5 ]0 G+ x
  } ) E9 M  V/ ^% d9 K0 f/ B
if (document.sform1.checkans.value=="")
, D/ R6 y# u- o5 ^7 I  { + b' s9 [9 X) [2 J# W( N  O
   alert("您的密码提示问题答案不能为空");
% R7 ?; L( N- z3 f' S, O- a' K( {   document.sform1.checkans.focus();     
& V; Y3 R5 l! n6 i$ K  b# O% S1 {   return false;  + L6 w' G: S4 L3 W9 @" W
  }
4 C/ C. R" U1 n; i8 ?! Z* B return true;     ! L( B! m. ]$ y+ ~- {) a
     
9 v! Y* ~5 d& ~& L- R} ! N% \/ M3 [( R. \
</script>

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