返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:  |/ [( }8 E# G; q- Z- ]0 G
<script language="javascript">     
. d; q0 x4 U- R0 L- U. ^function IsDigit(cCheck)     & ^1 d* b# S2 L) u2 k7 o7 r
{     ; p- m% o! C" O! g" b* e
return (('0'<=cCheck) && (cCheck<='9'));     # T/ O4 ~8 ]( [
}     
; Z9 y! @8 I- w* Y- _. e     6 o9 \& [# k+ z: [
function IsAlpha(cCheck)     
! N* _. E5 w4 j  b) y3 U7 v, f {     % K. C, ~* ?4 F( t# U
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
% Z1 n, _* g9 R; D0 j" j: \; A }              9 P3 _5 G3 k" S5 }; c& ^% m
      3 o- ]2 n3 I; j$ [" C7 _
function IsaNull(cCheck)         
4 |8 q5 x" ]( L4 k  n {         
: t' e- j" X) m, m! l* e" b$ D! W return(cCheck != " ")         
" e  V/ e. A' y" i2 E8 W) P7 D }                               ) H9 e4 R% D. A, h+ C5 L" C& x
      " |  t6 {5 R+ ~0 q; c; {3 L
function checkform()     
/ u& T) R$ D1 u{
0 Z7 o  x$ a& x1 u7 y, s* z/ E8 x  id = document.sform1.id.value;       A) Z4 M0 D7 }! g/ _. k0 o
if (id == "")     . N, J( n3 p6 p
  {     
: c8 m* b& J7 F& D4 a& n  alert("请输入注册名");     
% q& v9 i8 S5 Z$ c: T  document.sform1.id.focus();     ' v3 P! }& c! L
  return false;     
: v- e  {& ?1 [2 ^  }     
* S1 Q: \' k9 H/ a" S     
1 \+ C, C9 J" z. C for (nIndex=0; nIndex<id.length; nIndex++)     % N7 s9 I4 M5 T1 {) h) }
  {     
7 k- w( f, h/ C4 K# P  cCheck = id.charAt(nIndex);     
  p: b1 L$ S* ?( L& c+ a" Q  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ) e$ c! j. q: v0 {. I& e# g( {
   {     
! H( B5 [; y3 t" O   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     7 `8 g7 V( k' i) V' P3 {
   document.sform1.id.focus();     0 ?/ p5 R7 z  u* B: W
   return false;     
$ [6 e/ t6 c% q/ G   }     
" p8 B; ^9 m  P- L4 L, v& h  }
- `1 w% j4 l1 ^& D  b- s  chineseid = document.sform1.chineseid.value;     
9 t& `+ w/ y% s5 X7 ^3 v6 {9 t if (chineseid == "")     
/ i% K! G6 r5 K; P  {     & Z" P2 `1 ?& C/ v* N
  alert("请输入中文昵称");     % Z4 m- k  m  w' t, V$ n
  document.sform1.chineseid.focus();     
1 G: w. P, s8 B) p8 f; O' ]) I  return false;     2 m7 R- c" l2 z- ?
  }    5 k% r8 q7 k5 q0 x. t7 ?( k
password = document.sform1.password.value;     / r+ h; Y' O. O* U( `/ A" n
if (password == "")     7 g% x4 u, d+ O8 Y4 W
  {     
) o, Y# X, s& S4 h2 Z7 _8 G* O  alert("请输入登陆密码");     
2 x% D3 K7 y+ f0 ]& t% C& |+ m  document.sform1.password.focus();     
* d0 ~( q4 ?% g! s  return false;     
# v! p- e5 \/ \; l3 s) b  } : g, A. a# L4 V( T" X
password1 = document.sform1.password1.value;     
- ^) e" O- |3 Z8 [! p if (password>password1)     7 O* m3 v5 u/ `8 J) `+ {
  {! \9 I! g; N4 Y/ Y$ [- k
     alert("重复密码与登陆密码不相同");     
0 l! ]1 ]' z( a2 B  document.sform1.password.focus();
' o$ \& |% \' _% t, S                                document.sform1.password1.focus();     0 w6 A: b0 j6 Y" B+ f
  return false;1 B: C* {! y" {) D
  }  . _4 s3 e, J; H5 k" i/ @6 ^
if (password<password1)     
3 b# C5 T5 p% w4 L- H% F5 d  {+ y9 z! g2 I8 h# s) b' g
     alert("重复密码与登陆密码不相同");     
* x& t0 m5 g$ ^7 \) J/ J7 R  document.sform1.password.focus(); * T. E, O9 V* h! ]  X' S- h
                                document.sform1.password1.focus();     ' t" L  B0 E& F
  return false;
) N- h- p# `" Q7 f# b) N+ Q5 C  } & k- y6 ^4 m2 C0 v
if (document.sform1.email.value == "")     
  @* G' {0 N- x; `" e  {     
2 V+ C6 o# X8 v  alert("请输入您的E-MAIL地址");     
0 e6 Y/ U: j! s* O# B. n  document.sform1.email.focus();     # v& |+ k" _! S, v& r* h9 p
  return false;     
! h& l% W2 }6 H  j: f* U  }     0 F9 h) ]! U- ?& r
      
! B) s: v5 G% X. q6 R email=document.sform1.email.value;      ' P( r& W2 W% J& Z( {
emailerr=0     7 a  z$ w4 [& J8 [# V& a  `2 h
for (i=0; i<email.length; i++)     
8 t9 P6 A( m  j7 b. h5 w) H- W  {     
; ^) X, a  M1 ?  if ((email.charAt(i) == "@") & (email.length > 5))     
3 {. K0 ~, S7 w! d" l   {     ; Q+ C; v# l! C% C( f
     emailerr=emailerr+1     / Q% i4 i) ]/ `, a4 G
   }     
0 S+ N* F; Q5 b" O0 J1 `  }     
) j2 H8 c) Y4 l9 q if (emailerr != 1)     
) r4 W" |2 M4 F& p# F% }  {     
' `3 K& D$ T: S$ U4 G. |  alert("请输入正确的E-MAIL地址");     7 K( m8 w5 i' A  X! r# ~0 M2 ?! ~- i
  document.sform1.email.focus();     
. w8 u. O* K9 x# u. r5 C  return false;     - M$ H8 ^, M; d# |3 a
  }           0 \, Z/ o- ^- u! S
  $ D& n  R& L: d8 N' }4 f# Q! s
if (document.sform1.checkask.value=="")
5 \: L8 y% s& V. E  { $ o3 @/ Y. J+ j% ?2 l
   alert("密码提示问题不能为空");     ! C% N$ O8 _+ p( B7 n
   document.sform1.checkask.focus();     4 |2 d, k% g3 ~3 F7 e6 ~
   return false;  
" I' K5 [% h- \, r( N1 O  } ! M7 R6 o( U! X: v+ b3 m
if (document.sform1.checkans.value=="")
( K9 x3 a0 a9 L* B  {
5 e0 L1 @5 m. g0 E   alert("您的密码提示问题答案不能为空");
, D% p6 A& Q: V   document.sform1.checkans.focus();     
$ ]0 _, }1 t/ |, r   return false;  
$ f8 y0 K3 Z/ F$ m  }( S* f3 a5 u( m# F! D
return true;     : Q/ ~+ f9 ]+ x+ O% \
     
6 G- Z6 j  C! [" @/ q1 _}
: e: W' X* |+ e5 W# |! e; C0 K- E</script>

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