返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:$ M1 M8 o" z$ ^  D
<script language="javascript">     
, P1 j$ P+ U7 }function IsDigit(cCheck)     ! }' x. W' n: A3 ~3 y
{     + H  I: }* L! y0 S, ^/ O6 U
return (('0'<=cCheck) && (cCheck<='9'));     ( [$ u  T3 h- `) }1 _" C
}     
) u6 s- P( v% F/ T     % W( G/ ~) b0 d# |6 j
function IsAlpha(cCheck)     & o/ w+ n* c: o5 ?
{     
2 b8 f# b+ m9 f7 r5 ^0 f return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     / @: y& d; ^; D3 P' C/ S; M
}              
) o7 n/ [+ ~8 ?5 C) D: H      7 V! L1 \! J, q: d6 ]4 F
function IsaNull(cCheck)          # ?0 n5 Q2 c8 h4 X8 T: n
{          5 M4 P. j4 ^- E) P9 z; c: X# R
return(cCheck != " ")         
) z4 {& W, Z  k  h }                               0 q& {2 Z3 ?0 ]/ G
      
; Z* D8 J; V+ p6 Z9 P+ A+ Qfunction checkform()     
1 h+ @" R) m  v7 ^{ & A% T0 A# S0 ]" P* ^
  id = document.sform1.id.value;     , Q6 o; Q1 J" D) T
if (id == "")     
$ j- q# n; G; ]* A% J; V  {     2 }6 d, h3 L, X4 c
  alert("请输入注册名");     5 \. l6 A4 j$ y* e
  document.sform1.id.focus();     ; X; J5 p+ M6 u' ?) _
  return false;     9 c3 v* z' p4 G, D  o& e# D
  }     
2 ]8 C9 v$ R7 L     ' P5 c' }. ]1 j2 v: H5 g7 F
for (nIndex=0; nIndex<id.length; nIndex++)     0 z  b* {5 T% i! B* X2 a" ^
  {     ! |! B2 v- h- C. n2 u
  cCheck = id.charAt(nIndex);     ! p5 b9 F0 M! \3 {1 V
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     " i$ {' g4 M: J) T/ L
   {     5 W3 X" O/ V1 s
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");       I2 P/ }+ Y2 ?& A+ z$ Q+ ~" r
   document.sform1.id.focus();     ( [5 D, v7 O4 C
   return false;     
1 L  k& {! h0 K4 I   }     
4 T8 K/ L; @: V/ P5 V0 ]* A4 y% w! m* d  }
$ S$ }2 f7 M4 f7 V  chineseid = document.sform1.chineseid.value;     
$ O) ]* I2 \3 `4 P if (chineseid == "")     ! {, T& ~% J* P
  {     ' Q7 N* H  c7 j: o# X7 J( L
  alert("请输入中文昵称");     - r9 G+ e; v6 C, R9 _2 G7 r9 {3 w
  document.sform1.chineseid.focus();     
3 @* F' B6 L% l) J3 g  return false;     ! S% o( O; k8 E  |% S. X( W
  }   
( i8 m+ @% w1 U7 ~6 L password = document.sform1.password.value;     * \: p% d$ T- y  d' M$ ?& t9 s5 Z
if (password == "")     : y; t# p- `8 b4 c
  {     
9 Q. F4 P& a' |! d$ q: `: r7 e  alert("请输入登陆密码");     
! e  r5 S/ k6 {1 p  l  document.sform1.password.focus();     
. o% N" A: E- p  F' e; u  return false;     
- D, G' f* Y/ o( A9 F0 h( Z" N  }
, O8 S+ G' D  ^ password1 = document.sform1.password1.value;     5 |3 N2 ?% l" p! H* W" o
if (password>password1)       b8 m" D$ D9 Z# @+ w! U
  {
* v! r6 K2 x, e     alert("重复密码与登陆密码不相同");     
2 r8 f' s0 N! I9 d* Q7 Z. E  document.sform1.password.focus(); - |- F+ F. n/ ~5 R% `/ l
                                document.sform1.password1.focus();     
. \0 ]6 s( p% W  m; o3 C5 ]  return false;7 {- X* G2 o; G5 @$ D# T
  }  
* m7 u# U+ v$ C2 f4 c# S: Eif (password<password1)     
8 w& @4 M) u% ]) x; E  {
: @- d$ a- A2 o     alert("重复密码与登陆密码不相同");     
& a9 n+ H! d0 d5 D/ u  document.sform1.password.focus();
$ I+ b3 F+ I2 u                                document.sform1.password1.focus();     ; q0 B: _( q* P  P
  return false;* Z$ [, r6 e+ M* Q9 J
  }
! D* Y$ X5 [# \# n% I" w5 n if (document.sform1.email.value == "")     , K1 z8 e% L0 v3 B
  {     
1 |6 }9 ^1 G4 \; c  alert("请输入您的E-MAIL地址");     
! [( I. H5 E4 H. W6 b  document.sform1.email.focus();     0 g7 p& \9 Y: j6 w& v4 _9 ]
  return false;     
+ q, k) g0 M% {+ c* l& X  }     " k) ^& q; a( M* E- m
      4 o% o/ p$ w- o' X# F* M+ t
email=document.sform1.email.value;      
1 j5 u" m1 z$ e/ k" y( n+ w$ _% Q emailerr=0     : q2 @* y4 k* D4 c* |8 J
for (i=0; i<email.length; i++)     
4 W5 X2 c2 K. w) U/ \! K, y  {     
4 k6 n' i7 S- \% x8 a# @" @& c  if ((email.charAt(i) == "@") & (email.length > 5))     : J( ?  x  [9 x5 a- e* s3 }; |+ `0 ~( P
   {     . b6 X; }6 c: x) x' B  u) |
     emailerr=emailerr+1       m( W; j# L1 ~2 R
   }     
2 ^" e7 N) s8 @9 Z  }     
. w$ n1 Z- U- o7 H. U3 B3 m/ S* F if (emailerr != 1)     
# K* s/ j9 R2 `, K. g  {     
4 a4 B+ ~8 }1 y& t+ K8 d7 O# B  alert("请输入正确的E-MAIL地址");     % r- _& j" o0 l& p# n
  document.sform1.email.focus();     
5 v* c6 Q/ D# _7 I& b& n! F  return false;     - `3 W3 w' O. O2 S
  }           - Q4 ]5 B& s2 W, n) V( U; l; P
  - U! G" o  X3 `  Q
if (document.sform1.checkask.value=="")
2 T+ Y, V7 d% M- e; {1 E  {
% K! Q* b1 n" @% p2 g   alert("密码提示问题不能为空");     
+ u+ _6 h' S5 U6 ]/ y   document.sform1.checkask.focus();     7 r0 H2 S6 m) A0 s
   return false;  4 M$ P& y& p* y8 p2 \/ R# @2 w
  }
' r, E$ y) r3 ]; q' ^) N if (document.sform1.checkans.value=="") % x2 {- W' n" g. O- m4 i# p
  { : O! P6 w* O1 E+ ]3 ~4 i4 J
   alert("您的密码提示问题答案不能为空"); 6 ]; c7 r6 s- l
   document.sform1.checkans.focus();     2 y8 V( U; g* w' q+ f
   return false;  
. ~( _  X( D; O4 }  }$ g3 U9 ~  F' g+ m& Y) m6 r
return true;     1 u: e) X: Z, }
     + W9 P! |3 f9 m3 y& Q# N% `5 @
}
; C8 A" k; d5 q</script>

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