返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:/ u! v' K1 w5 K3 s# V8 x
<script language="javascript">     4 U5 @9 S/ `2 {9 s. A# Q
function IsDigit(cCheck)     
+ f" E5 p7 @: h {     , o  ^( K6 ~* e  O
return (('0'<=cCheck) && (cCheck<='9'));       s# `6 }& b, M6 \! E* D; D- v4 m0 y# h
}     
. l6 T" A' H) D; V     
6 R% x! A  p8 ?/ G0 ^6 ~function IsAlpha(cCheck)     
6 w; X; Y- x* |8 H1 G {     ' B3 D4 f7 O6 c4 ^; \3 b
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     1 f$ {' F2 N5 M
}              " I% S" J  i. m3 l) K* P) E( c# M
      8 d+ R1 F- n' q- q
function IsaNull(cCheck)         
. Q6 w1 S- [5 I& @- j8 h$ S {          / _* x( }4 Z/ v* S
return(cCheck != " ")         
: ~' h, `9 [. Z }                              
" q" j; I, i+ C0 o8 R, C" O# v+ [0 X      
6 m* U7 j' F6 `function checkform()     : b" K; U* V9 L# q
{
5 [7 ~* c4 [6 `; f3 k  id = document.sform1.id.value;     
8 H9 c) C* v4 Q& W4 V if (id == "")     
2 T) x  S6 q& p- t' r' k. o  ~! U  {     6 h, V( i* v. x" X( E
  alert("请输入注册名");     ) |/ n3 H0 j$ r8 v" G- M: A  ~' g
  document.sform1.id.focus();     
. b% ^3 ~8 H7 v2 W  return false;     ) y* V8 ^9 g. |$ L: G8 z) A
  }     1 `- w) k' A3 B) Q% K; w/ J# u6 P+ A
     9 Z5 t; V  ~* r5 `5 F% [
for (nIndex=0; nIndex<id.length; nIndex++)     
; W! h. C! @, Y# Q2 e  {     8 m" S# j# f  \. y1 C6 k
  cCheck = id.charAt(nIndex);     
( a! b/ R. T. n, O3 V2 G  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     1 _7 F1 r3 v2 n! F0 U
   {     4 o8 k( }+ v6 K7 U
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     % j3 w2 q( t. e  h, H" J- T' [1 T
   document.sform1.id.focus();     ! g) Q( E2 ~0 a2 w" k
   return false;     . r: m8 s: z" L1 r. K( i% l! w
   }     ; p4 s. X& G( u7 M* W6 t
  }
9 U8 I! K, @9 |  chineseid = document.sform1.chineseid.value;     6 k" R! E6 y! u# `8 l
if (chineseid == "")     
2 N( o- W0 S  W, L  {     ( P& k4 |4 T+ @, l- z, _! G$ [4 p
  alert("请输入中文昵称");     
% d. O- \% t% _. a; J# N9 O$ G* Y$ M  document.sform1.chineseid.focus();     
# Y( `* H  [7 B! N. {) D7 T  return false;     4 Q' ]- a! P" ~' x
  }    # C: A# O. q6 E  h; T5 k9 z
password = document.sform1.password.value;     
3 M% M  O2 G+ W* u# v4 u if (password == "")     
' _7 I: d# B$ u4 ~" K5 G8 _& q  {     
. Y9 k9 d" W0 a' b  alert("请输入登陆密码");     2 N0 Z: x" k% `& I
  document.sform1.password.focus();     
! i" m7 r- h) o2 O3 i- U! ~) |, V3 C  return false;     6 {1 {& N$ r; f( u7 s/ A. Y
  } ! |3 l2 X: P  D0 ?# P( w
password1 = document.sform1.password1.value;     - ^1 C3 }9 h5 Z
if (password>password1)     
% w1 P3 Y1 a% l  {' N5 u: a: ^$ j' W8 K9 P
     alert("重复密码与登陆密码不相同");     
: O( }* U( b% S, Z  f# W  document.sform1.password.focus(); 0 H2 z" O% `$ k  G8 O7 {
                                document.sform1.password1.focus();     8 F6 b5 _+ F% p
  return false;% ]; \3 T5 Y) L
  }  
+ f" z/ q3 c0 |" N3 Fif (password<password1)     ' G+ x# l' z/ J3 e, C  V- E! P& ]
  {
* l) y& e8 l; H" I. h     alert("重复密码与登陆密码不相同");     ! P; j/ E8 l0 I8 K! I
  document.sform1.password.focus(); , g" \" o% p2 R5 D* s+ H& M, h6 U- k
                                document.sform1.password1.focus();     # @: F, r% p3 ~) {
  return false;
/ _& h4 {2 S" z+ h! N) [) J$ j  }
3 c+ H" ?9 P: Z if (document.sform1.email.value == "")     
* e" N/ B8 ]2 ]) x  {     ) K8 X3 y0 r% t" s/ K
  alert("请输入您的E-MAIL地址");     ( ?, |4 _- b: P
  document.sform1.email.focus();     # f4 Q; i7 z+ D3 w
  return false;     
( `( x1 S9 L  R# X; `  }     : o% O. g. ^0 ^+ g
      
$ {( {! v6 G- c5 v0 Z! R$ E- C email=document.sform1.email.value;      
8 k+ T% B. B. @- R+ u* d  h" q emailerr=0     3 o: j% o! I4 ~+ M, a
for (i=0; i<email.length; i++)     2 n/ C9 F8 b9 [3 f/ O# N/ c9 o) l
  {     : E6 G) c9 C7 t
  if ((email.charAt(i) == "@") & (email.length > 5))     
: E+ o* N$ A* k% h! G   {     & Z2 B2 M6 \  m* |7 `% E' s
     emailerr=emailerr+1     1 x  Y) t1 W6 I/ Z% U: n
   }     
5 z9 {7 h7 b; F& [  I  }     
$ ~, ^! R1 t7 G3 S8 g if (emailerr != 1)     - X7 d; }( O( v2 }
  {     
1 }1 A# e: M9 l0 D! J$ z" A  alert("请输入正确的E-MAIL地址");     
0 i' Y: ^: P4 b' z: U  document.sform1.email.focus();     
- x9 \  H3 Q  y, {4 Z- j  return false;     % W) @# s9 v# ?% Z8 G0 v' l
  }           9 N! E: V( g$ n# V, m5 g
  ! c5 z$ A# e8 `, \% y# ?4 J
if (document.sform1.checkask.value=="")
, s6 @5 e  n* H0 _. |  { # E" O# y# _0 ]8 N3 |' ]
   alert("密码提示问题不能为空");     
& H7 C& K* a3 l   document.sform1.checkask.focus();     ; z: U1 U7 E7 y) ~% h' B6 A
   return false;  - a# i% d; i+ N8 h$ C
  } 3 H) a. n$ Q2 m5 U3 I
if (document.sform1.checkans.value=="")
% c: w; ~# ^+ p* R& y* D# L& R. V: @  {
7 F' ?. ?% K3 \# T; R, _& x7 l  D5 E$ B   alert("您的密码提示问题答案不能为空");
$ i5 T3 `6 Z' k0 C( g* {/ p* @& T: p   document.sform1.checkans.focus();     2 K& O$ [. a0 o8 @
   return false;  
' G% M3 U8 R9 u5 B- L2 a  }0 Z& K  V! ^9 H$ B1 e; }# K; l/ A
return true;     9 F, l5 P, B/ Z
     . c; F% u9 d, L" U! @5 ]
}
, F6 G3 f  e' g: e& b0 R. a7 p9 ]</script>

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