返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
: U% X1 d6 I; h( O& W/ E<script language="javascript">     
' m' c1 h$ H8 z: S3 X0 qfunction IsDigit(cCheck)     , Z: t7 G& M. r$ F
{     
7 @& P$ E" l/ P return (('0'<=cCheck) && (cCheck<='9'));     ( r) r6 X5 M% O# v# _; P1 U7 b: L
}     
2 g3 T- b' w( u) ^/ d     . k0 q" ?5 ]1 b. |. ^. ~
function IsAlpha(cCheck)     
* w4 f% S2 M4 p# o" O {     * S: \7 ~% F8 |$ L
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
4 U. x4 D  ^+ [* ]0 @ }              
  E7 g7 ?/ R9 w      + n4 G- o2 g3 C6 Q0 Y
function IsaNull(cCheck)         
7 h7 W# g3 |/ e' P6 @# ]$ M3 G {          , C# Q2 Y) X( i% E5 i( [; j% o7 ^
return(cCheck != " ")         $ k% t# j, p1 c6 I% b( u
}                              
4 f& y* Y( H5 J4 Q! D( r      0 d2 l- c$ X! Z+ E2 h" ?& t
function checkform()     ' @, H( i" M7 _' B1 d
{ 1 N* G" U8 Y% ~( s5 n- x
  id = document.sform1.id.value;     
9 X; E+ i; K  T& o8 O if (id == "")     
6 g' F- {  {  e  {     8 V; c$ x- x. _3 h1 x
  alert("请输入注册名");     8 E) f8 [8 }3 U9 t+ H% ]/ T
  document.sform1.id.focus();     8 Q5 Q% K. S/ V; _" P; \" j+ j
  return false;     5 C  [  D( K8 f/ A. c% l# V
  }     
8 }0 Q+ ~: i, D3 s" n     ) `$ j  g# f# X' f6 F" z9 w
for (nIndex=0; nIndex<id.length; nIndex++)     + b: L- h% h' _7 U$ M$ ?
  {     
% `2 H1 I. q* H  cCheck = id.charAt(nIndex);     ) n# F7 J4 C: q; Y* b
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     , Z# k" M$ i, R$ O5 R
   {     
, t" |- _9 ~+ {; _  O& `: R( d. ?' U5 E3 h   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
3 r% }6 N2 ~% w# Q7 |   document.sform1.id.focus();     0 k6 b! y6 B% J3 h1 U. W
   return false;     - f! x5 O+ V& x8 }. s6 H8 o! v
   }     ' W  o$ e8 X1 @! y7 I( H
  }
# |8 T) V3 j- }8 U: e: c  chineseid = document.sform1.chineseid.value;     
5 f9 F5 c3 B8 m/ c if (chineseid == "")     
+ W: q1 |( b7 B3 r# a7 z  {     
/ |2 Y, [, Y2 y' _- q1 F  alert("请输入中文昵称");     ! n0 e( U0 B; H+ ~0 A
  document.sform1.chineseid.focus();     8 s+ m. ~( z- A
  return false;     
# E+ t7 @5 r2 I" J2 a  }    0 L) N$ F, Z$ ^& X0 d* k9 [7 a
password = document.sform1.password.value;     
  S; [& V+ ?: U' ?3 F$ J: }7 ] if (password == "")     , B0 L6 A5 X* a- B- W" B( \. A
  {     $ |+ v6 q: w5 y2 n' ^1 E; L
  alert("请输入登陆密码");     2 [9 P5 s$ ^+ v* D
  document.sform1.password.focus();     , J# G7 g% c6 U1 E) b
  return false;     . Q: N4 P) y; ?. U$ s
  } . x  t$ K9 r6 h. R
password1 = document.sform1.password1.value;     
, Q& ]; f. K) `. V4 I! q if (password>password1)     
( B' V0 K  G2 N9 m& y" i  {$ \& k9 B& }. F
     alert("重复密码与登陆密码不相同");     
& `0 O/ z, y/ O4 g; V5 ?/ A: n/ u0 `  document.sform1.password.focus();
" h, ]* v* ^  ^* o" R                                document.sform1.password1.focus();     % p1 v$ C6 j! {
  return false;
# C3 V( ~" k/ j! C! k' m  }  , g9 m. H# t8 x
if (password<password1)     
, T( s+ q$ H9 Q4 ?, S: C  {
2 [6 y. i2 Z- a% ]$ W     alert("重复密码与登陆密码不相同");     
6 M0 e7 j. N5 d7 e6 b: K+ m  document.sform1.password.focus();
0 ]; r$ Z- T7 m" O+ @                                document.sform1.password1.focus();     8 Y8 `$ w- Z4 b% `/ Y; Z
  return false;
6 V9 F: W. B+ E, I( w  } ( i; Z0 ^1 n/ T: r6 C. S3 ~+ f
if (document.sform1.email.value == "")     
5 v7 }) Z, {. j2 y& V8 q" x  {     * Z, p* u2 d) `  K6 G
  alert("请输入您的E-MAIL地址");     ) G' ]0 |. y2 h
  document.sform1.email.focus();     
9 Z2 X9 _- l6 {! K  return false;     " Q. B% t* ~2 e/ k& M/ I" Z
  }     ) a. I( q2 L: r  f8 U6 [( ^5 I
      7 F: C, b2 i8 i4 e1 A
email=document.sform1.email.value;      
6 Q1 [" P# i  P  n emailerr=0     : v) T* \$ ]% K) u, h
for (i=0; i<email.length; i++)     . r$ v7 `8 F' V" f
  {     
; E+ Z4 q, r8 ]2 z3 Y1 W' g  if ((email.charAt(i) == "@") & (email.length > 5))     5 K6 h& g( M$ S9 W- d0 a
   {     
, I4 b' u/ z1 [/ @     emailerr=emailerr+1     
) t4 j( f9 _9 v* A5 s   }     
  m  O! w; T9 h& K! f- O9 k  }     
: b, f# D% G3 F" b if (emailerr != 1)     9 l# f  a5 T9 o3 n
  {     7 D  G# O) w  b* i" y$ X
  alert("请输入正确的E-MAIL地址");     
- @2 z* W& a3 F4 a& S' S- v1 Q# g  document.sform1.email.focus();     ( i. G1 t2 |1 m
  return false;     ( F6 A% ^1 m: X
  }           " Z* a+ L' S3 I+ y
  9 W" q) B% f- `4 O
if (document.sform1.checkask.value=="")
! A% F, g. b% p8 I  {
+ t! }/ T9 C! }; `2 m2 I  `7 q   alert("密码提示问题不能为空");     0 \% o% x9 k! l- T
   document.sform1.checkask.focus();     * x+ Y0 e0 p- m8 X& h
   return false;  
, m8 X- i, {  L0 Y0 Z  }
! E3 e1 \% m  W if (document.sform1.checkans.value=="") 6 A1 m2 f/ {  C- [* E7 U2 }; v0 k
  { - R- [1 `& ?+ F( J  K4 \* K
   alert("您的密码提示问题答案不能为空"); ; d/ N  d# K# c+ V# K
   document.sform1.checkans.focus();     
, J% w$ ~7 L7 c& t! c   return false;  
4 h1 i: C% e# F5 u. w- H& v1 M0 J  }
# E  q/ D0 j2 H% f return true;     2 t; B' i7 I. r- G6 J" w! g. ~
     " H4 I: f5 [& J! t* |& A/ K, @
} : m8 s' H7 o% ^5 n
</script>

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