返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
- K5 x" p7 g% \2 E: ?. V$ f<script language="javascript">     $ D7 P8 h( s+ M. `# I
function IsDigit(cCheck)     
) @+ N6 U  F, I! w. j# \ {     
& {% ]( F0 G, U9 d* f- m+ `+ k return (('0'<=cCheck) && (cCheck<='9'));     
2 C% ?2 s) R& t0 g, X }     
( C0 z" k5 f+ @. o     
5 ~* |+ x1 f2 _" Kfunction IsAlpha(cCheck)     
& X  C8 E, l; o5 M. ~- v {     
  ^" {! [( c, R2 z0 l, ~ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
# G  e2 Q1 n  A9 t7 m4 E- x }              7 \+ |$ B6 J1 s( a+ |& [; Q: k2 o
      
/ c* ^. u4 N' \function IsaNull(cCheck)         
. P8 }1 g0 ^! i+ O: e {          : j  |5 m$ s. w! o
return(cCheck != " ")         ! c+ q9 l3 v# T( u8 j7 M3 s
}                               2 H- S+ `* O1 J: g4 i- l
      
% k8 l" v/ u8 w+ K7 l. l, @function checkform()     
8 U: W" H6 k$ ?- J{
) G4 S/ h0 [" k# J* X9 s! B  id = document.sform1.id.value;     " C5 V" S) l, Y
if (id == "")     & G4 q/ V) `/ q& n/ u  ~
  {     
0 ?% G2 B) Q& J  s$ W" Z0 K  c* f  alert("请输入注册名");     ( }: ]! x9 Y# m3 b1 Q5 v
  document.sform1.id.focus();     
* g& u- ~- f* N! u) P  return false;     # ?; H. D; E: I* w7 s- p
  }     # b: _$ k% E, E5 h/ |5 Z
     , p$ q) n; P$ w+ @$ U- \
for (nIndex=0; nIndex<id.length; nIndex++)     ( ^! V( q7 T0 f  _2 f
  {     
8 k! p& T. k* m  cCheck = id.charAt(nIndex);     
4 M- g! ~3 r$ e  g  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
1 g% p# M9 E8 ]1 l6 X6 O3 V   {     
$ k9 }+ e" ]3 U   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     # ^  u9 d" K" y9 R
   document.sform1.id.focus();     
6 I% g! H& t: @2 i/ v( b   return false;     9 z* a7 Z9 g: e  }+ D/ ^( y
   }     9 b2 U' p* f7 _4 t" S. b
  } ! f5 D% q2 i0 k8 Y7 I' W( V, A
  chineseid = document.sform1.chineseid.value;     
; D( p% u# K) q if (chineseid == "")     
; H# g7 c4 `6 w0 d* ]  {     
6 f, Z" O. a9 `  alert("请输入中文昵称");     $ T/ t9 Q3 i5 C' N/ ]6 Y
  document.sform1.chineseid.focus();     
( C. N; L# \4 l( i, @% l) h  return false;     
. U; x. ]: A% K( e% p7 _9 M9 o. O  }   
) M  X# K2 b! e, ` password = document.sform1.password.value;     
* j# _! `& e& u( x: Z* {1 s if (password == "")     4 q  v$ z% E5 g$ `7 M
  {     9 u" v# R4 L& H& g* |
  alert("请输入登陆密码");     
) |* \( t0 z) `" G  document.sform1.password.focus();     7 _. c  P5 d& J. |  Y& i6 X
  return false;     
& n. R- \! e* P* y3 ^  } 2 m5 c. m! B* a+ O7 \& l. y) f' T
password1 = document.sform1.password1.value;     
# s6 }1 F. ?, N7 Y$ y if (password>password1)     % t6 I" O5 ~+ I/ E8 F
  {
+ [4 ^6 a1 a. m* N2 P  L! U     alert("重复密码与登陆密码不相同");     - @! Z. b# C; S5 n- W  }* |
  document.sform1.password.focus(); : H4 v+ Y2 S0 P. M, h9 v
                                document.sform1.password1.focus();     
+ F9 @/ ^# P% n/ a( i/ L- Q" i  return false;
3 V4 l; s, f1 ^$ t! e: t/ r  U  }  ' I* p! |) V( G3 U0 ~
if (password<password1)     
% _2 H6 |- `$ O/ F/ ?  {6 `+ T/ E  G0 ~2 `
     alert("重复密码与登陆密码不相同");     ; C% c. E. }6 \7 O# k0 B& ~4 f& H
  document.sform1.password.focus();
0 N& B8 m9 `0 _( O9 z" }                                document.sform1.password1.focus();     
) J( q: B# v) r: w9 a1 d: a0 [. w  return false;( \6 `$ Q  F7 H6 N; T, o
  }
! Q, g) W" R+ y4 O$ I0 B if (document.sform1.email.value == "")     4 R+ b# E# P+ Z4 L
  {     
) s1 S; Q9 {2 v# D  alert("请输入您的E-MAIL地址");     
  L3 V) }, t" A3 H6 W& r& E- G' m  document.sform1.email.focus();     
; `0 H0 g) x+ T  B* q+ R  return false;     : @' m: {9 O  v
  }     8 b" P# `0 i8 Z+ M
      
9 X& ]) @% L2 G! C5 [4 Z8 y email=document.sform1.email.value;      5 T3 M# L+ i, \' u
emailerr=0     
1 P* d6 @. a; G) L for (i=0; i<email.length; i++)     / U; P/ C. c- g8 M" w
  {     $ L/ j  p- C0 V- t& d5 W8 I% F
  if ((email.charAt(i) == "@") & (email.length > 5))     
8 }( r8 b  g3 I( m; C$ X7 q! I   {     
$ E/ \- G- b, K& x( D7 t     emailerr=emailerr+1     
" |4 }+ x2 g4 k  i! ^2 l( @4 @   }     
6 G. n6 j- ^6 d* S; G* l& {) }  }     
( N" I# y" r/ t0 C" R# u if (emailerr != 1)     
( a9 ^+ |# R0 s' {" e/ h  {     4 K3 ^3 }' X- a0 j9 D* ~
  alert("请输入正确的E-MAIL地址");     
) [# h, J# o" o0 O% w( P8 }0 V2 F4 O  document.sform1.email.focus();     
6 O  g( C2 X" [3 o8 Z1 z' j  t  return false;     1 ^7 ]/ L* }; g# i; J
  }           
7 W* s+ E; _8 N/ O# E. I4 |  |' G+ }6 Y  
; G! C& _6 a9 z9 q; F9 i if (document.sform1.checkask.value=="")
5 g0 R* E, j: c; e/ z2 ?  {
$ ~) p" ?' j# l2 L   alert("密码提示问题不能为空");     , a: U1 i' p& E
   document.sform1.checkask.focus();     7 W1 t( ]9 w$ D8 f) x. ^
   return false;  7 G2 W& D/ l8 c8 L
  }
# E0 `' G1 k9 Y, o3 L( f; c if (document.sform1.checkans.value=="")
& ], {5 }" L6 d5 m  {
. O( N- d6 j1 b2 J* S5 J   alert("您的密码提示问题答案不能为空");
) }& N& j$ D7 P  H2 b0 R: {/ z% Z   document.sform1.checkans.focus();     
$ r4 M/ N+ n$ `   return false;  8 L4 C0 f8 Q* [2 ^2 m" f0 N. d, u
  }
4 t# e* x& v3 b% c return true;     / \2 ~+ o/ _' F0 Z: c
     * O( k% j+ t" n" C% q6 K
} / N; R" _2 ^/ r0 X
</script>

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