返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:, ^* Z9 b" t1 _9 u7 y, ^
<script language="javascript">     ) G5 O  G- n) {  F
function IsDigit(cCheck)     , v" J$ W0 Y( U( P( f
{     9 @9 V; ?! h) g0 J& _% y* _1 \
return (('0'<=cCheck) && (cCheck<='9'));     
+ d" t% i2 y- C- Z }     
+ g8 d. f( E- w; E) I, W. _5 O     / {" a9 o3 D6 [0 ]: B4 Q
function IsAlpha(cCheck)     & K4 |! l2 L6 s: e  f
{     , g5 O5 {3 b  Y; U
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     7 I- `& Y' }/ F1 i
}              
4 J& O3 s, W) r( v  f- ^7 _      
  s4 G' M0 Z! Pfunction IsaNull(cCheck)            u" v( g* P" R# v
{          0 e( V% p& _! Z  U( ^; k
return(cCheck != " ")         . [8 }- ]8 B- I8 u5 k* f  L% |
}                               5 W* |7 @: w7 A/ j4 k  W$ U
      . s3 T2 S$ H4 m* N
function checkform()     
; e0 R; Q8 l% O# |' b$ i& d{
" o4 T5 B& S% ?3 s+ ?1 K7 `: b  id = document.sform1.id.value;     3 u. g5 I. S& h' E
if (id == "")     
* Z7 {6 t- F6 h# k& m- z/ t  {     
3 q! ^+ s/ k, U, n8 y  alert("请输入注册名");     ( |# C! Q" Y. L/ n" _' s: [
  document.sform1.id.focus();     
+ ?0 f, @  N9 I' I  return false;       q, q8 A7 o7 [. X# \+ K
  }     
' O; Q! z) r2 u# J6 B- Y6 |7 x$ ~     
9 K! V6 P- ?' x! |8 J$ I% Y for (nIndex=0; nIndex<id.length; nIndex++)     ! f! M7 u* O+ P3 w& E+ S8 c
  {     
* G; q. _+ c( }4 S7 v& g  cCheck = id.charAt(nIndex);     
2 I$ w) p& `" E1 |5 Y6 k  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
) V; C6 k/ ]+ c1 {   {     
- [$ D6 d$ F* n. A1 l9 ?   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ( ]& l& J6 [6 ]2 Q" _$ B, z
   document.sform1.id.focus();     
; m0 _3 n" `; C3 z1 r3 m   return false;     
% X/ _, B; H) D9 s6 c   }     
8 {' N. z/ j7 r2 F2 Z4 x, G  }
: S  C5 E7 A2 _, f  chineseid = document.sform1.chineseid.value;     
/ W0 N9 i6 W, M7 \ if (chineseid == "")     $ O2 z2 G* y& {/ R5 [
  {     ( g: q5 M. j7 t9 y# x9 K. G
  alert("请输入中文昵称");     
2 A- V3 s3 C& h6 q# z3 Z" v  document.sform1.chineseid.focus();     2 U) y3 F1 K* g/ a, d
  return false;     , E6 {9 S/ X  p% c5 L! F2 o6 \
  }   
9 P; U  T) c# ?2 i password = document.sform1.password.value;     
6 ]; M2 A2 g+ r9 [$ V if (password == "")     ' `7 f: S  f$ D! o$ ]% q' F8 M
  {     
5 v* w! t# i) E) i  alert("请输入登陆密码");     
3 A2 z" H! I6 \+ S9 {  document.sform1.password.focus();     $ m, f8 a; c  o, ~' M8 T
  return false;     
/ D9 |$ x1 t9 Z9 \2 O  } + P! f4 I; i- I& ~' w0 S$ p
password1 = document.sform1.password1.value;     5 I: {* B7 F5 H4 L  Y
if (password>password1)     
/ _5 ~9 u! v7 d+ L# {/ b  {6 i" g. ~8 e9 ?- p1 v
     alert("重复密码与登陆密码不相同");     4 K0 j$ E% s3 A
  document.sform1.password.focus(); 0 C6 V; C. @; Q
                                document.sform1.password1.focus();     2 J- k9 T$ H! K; O
  return false;
4 i8 Q/ w' O; W! \* y  }  4 @) J. {/ [, ?& I
if (password<password1)       O  u' ~! `* |7 a5 V6 D' r
  {1 B. }7 p6 c7 |9 T/ [
     alert("重复密码与登陆密码不相同");     
- O) `) k+ Q' p3 B5 Z. ]  document.sform1.password.focus(); ! @) Z8 `( a8 |& j* R* B  `
                                document.sform1.password1.focus();     7 e" ^, @+ |4 _: s- E
  return false;- Y0 Q# Y. M5 K3 ^
  } 9 C6 |+ |( L3 x" D
if (document.sform1.email.value == "")     
7 ~7 i7 m1 H3 Q/ S  l0 d1 }  {     + a+ s$ z! [1 Z8 |6 w
  alert("请输入您的E-MAIL地址");     2 @5 R# x' s, ^! f1 ~7 b  ^% `# N4 j
  document.sform1.email.focus();     - E0 r! H; p; }# m# i5 Q
  return false;     
# `0 p( Z+ @/ I  }     . P/ G8 g) C3 X# q. l
      ; t% v- I' h! ^% j3 `( A) Z
email=document.sform1.email.value;      2 Y( O3 F1 A$ M5 D+ T! R0 o
emailerr=0     % w8 m% r" X4 i- a
for (i=0; i<email.length; i++)     
1 U* p! d, i( U8 l+ h  {     $ ^$ _5 ~/ `. H) m& n1 a
  if ((email.charAt(i) == "@") & (email.length > 5))     8 S4 V3 E( M/ O" F' Z& W
   {     
9 F3 n' k, l' [; D. U9 j     emailerr=emailerr+1     & W; w# @" _- {( _" u
   }     
5 E' O& g/ F3 v$ [8 w  }     
: b; o0 Y7 `1 P7 V  h% M0 A/ U+ m if (emailerr != 1)     
4 N6 V( d" A$ m+ D8 u  {     
8 S3 c, k1 k* ]  alert("请输入正确的E-MAIL地址");     8 t1 F+ E; ?) ~+ b" Z4 x
  document.sform1.email.focus();     $ D8 o9 l$ g& s: f: R
  return false;     ' [- A7 C; a. M! G2 M* ?
  }           
( R) ]: s/ a- `. |; r% |  
* u# l0 P5 \/ M if (document.sform1.checkask.value=="") " F8 @3 b& z8 s" }* X0 b4 p
  {
0 A/ l9 I- l/ I1 \& d/ g$ ~& @$ m   alert("密码提示问题不能为空");     / V5 s- y3 _- X/ \# i9 D
   document.sform1.checkask.focus();     
, c0 v- I# {1 H& W8 w# i   return false;  1 Q7 y7 B7 {7 e  Q0 W- d1 p
  } 0 R3 C9 I0 p) [' n
if (document.sform1.checkans.value=="") ! k2 @* {1 g% f7 r
  {
% H' z# W2 }8 X* P; m   alert("您的密码提示问题答案不能为空"); + V9 [& J* t+ V" _4 E  [
   document.sform1.checkans.focus();     % h: w& |$ S! B# i+ E
   return false;  % r) G9 \6 l- C
  }1 ?/ _% Y0 J. j' B, x/ y$ m$ V
return true;     + e& @1 ^% s6 k2 q
     
( C( J% ]2 }+ @% U5 D8 L) S$ n} 0 P  W# d5 ^7 L5 [6 t6 {
</script>

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