返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:' T) j# u  C+ M0 o8 a/ |+ o
<script language="javascript">     / }! h: e/ C+ A; V1 Z
function IsDigit(cCheck)     
) A! W7 g- b: x9 ~9 G) j% A0 g {     $ B: O( b! d* ~: n* O% u
return (('0'<=cCheck) && (cCheck<='9'));     . m# N3 L- j& X( j
}     8 b: K7 H! `6 ?/ C' U+ s4 l
     
. Y$ ~+ z; D* a( zfunction IsAlpha(cCheck)     ! {3 X3 k4 ^& C3 f8 y' `
{     
5 N8 g! V0 m- s9 x3 |. |( I return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
& w  o3 X0 n/ a8 i }              
* R* D8 w! z" A/ W  o) p% ?6 l      * E$ K2 d  A# e
function IsaNull(cCheck)         
- j( d* Z' |9 s5 t% j7 i) Z6 M9 e {         
/ I* ?- z& l" W8 ^. {* c8 k return(cCheck != " ")         3 k6 l6 e- j+ h  W
}                               0 K& j7 i6 z9 T; k: O8 ]: N% A$ k+ l
      ' ^. P* j& d- f6 d. d: }# c) k2 n- O/ p
function checkform()     . ~9 E$ _- h8 I% c$ w, L
{ 3 [, L" x0 [+ s/ b- g
  id = document.sform1.id.value;     ) b8 q. I) y7 @, L1 Y
if (id == "")     & P7 l. K) m! }% X& N, G; Z
  {     - ^( n6 Z% N+ E& ^+ v
  alert("请输入注册名");     ' S. G/ d' U/ P9 v; e2 Z
  document.sform1.id.focus();     ) g6 Y2 C: @& e0 l
  return false;     - J5 H4 r* w; x$ x' @
  }     
$ A' q% N$ n5 D: I  @& K; \     ) T0 k$ S) T. r/ L. L: O9 b
for (nIndex=0; nIndex<id.length; nIndex++)     # ^) O9 h4 ~, K2 x3 G7 m) o) O
  {     
% W6 v1 D6 H# K; l* t% E# |% o  cCheck = id.charAt(nIndex);     
6 }9 s2 p2 Q/ K, c! N: V6 C  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
0 B- u. A0 t, w/ J   {     
, o2 z. j. }) }& Q; C3 r. I0 U! S   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
* d% M* Q; l- r   document.sform1.id.focus();     
& S5 c6 Q$ s( r' [# c   return false;     
4 K% w$ `: Z% o/ [6 a" W7 Q0 m   }     1 t0 c- r% ?) S
  } + K0 {( f% R# r( l( F
  chineseid = document.sform1.chineseid.value;     
# E2 t& w, H+ W0 D/ H$ t: a  f if (chineseid == "")     
) v% ]* W2 ~$ g' p) r  {     ' R  j) E( W0 V  l3 D4 k1 L. F3 q6 E
  alert("请输入中文昵称");     # r8 a3 `1 ~, x" E8 y4 _7 ^- Y3 o
  document.sform1.chineseid.focus();     # ~$ s5 s( Y% j* s* m- l
  return false;     
' x) u+ P; j6 ~# b4 V9 x& z  }   
) b# M' N8 x1 R5 F0 s; w password = document.sform1.password.value;     5 V6 C9 g9 N/ t, |% H9 ~+ t# A
if (password == "")     : z0 i. O: L9 T1 ^. E. ]' j
  {     3 _: k2 l9 w' e4 K' K
  alert("请输入登陆密码");     
% M( W: p, O6 J  document.sform1.password.focus();     - Y) X$ f8 T& \6 v% C' G( X
  return false;     
# F: p4 D) r* H$ E# s$ z" D7 M% Q  } # H( {& \' Q3 _* w+ ]0 P  ^
password1 = document.sform1.password1.value;     
3 q! @# Q  \* W5 ^+ Y$ h if (password>password1)     
' I! ?3 X. H: t  {
: ~- j+ _7 d, r: F1 W5 b  H! s# N     alert("重复密码与登陆密码不相同");     ( L7 K# e; X; R- Z3 S2 f
  document.sform1.password.focus(); 2 L5 C! {4 z. _% X* W1 J- E
                                document.sform1.password1.focus();     $ |  [! T- |. u, [
  return false;1 w; C! O7 N9 e: Q) n
  }  
; Y5 A' e  r' q3 H8 oif (password<password1)     7 G$ c6 Z& o: p+ @# f" o
  {9 _5 s% D% |) f- I# G1 p& p( X
     alert("重复密码与登陆密码不相同");     
. i$ f0 y5 I0 e* w  document.sform1.password.focus();
" J# H& j+ z$ Q* x- O                                document.sform1.password1.focus();     
% k6 O; A: s5 S5 B' T* h; V& t  return false;
/ e# `2 z7 k9 I2 S  }
  q. `3 x7 T! [4 [* s0 F& v6 u% z if (document.sform1.email.value == "")       h) n& r3 {/ D  i* V
  {     $ J, s$ ?) I# p
  alert("请输入您的E-MAIL地址");     + ~% f7 V/ q' r6 E" c+ i
  document.sform1.email.focus();     
7 H3 Y8 i+ T6 g9 F7 e  return false;     
! o7 x% Q* |' f  }     
/ F* Y+ x  P7 ^& K  p        ]7 S9 u5 a& N* C/ T- q
email=document.sform1.email.value;      
5 k6 g1 j, O/ a! I9 i3 E9 o) t3 b emailerr=0     
9 \2 T9 f2 G7 E6 F1 b$ d9 m" b for (i=0; i<email.length; i++)     
' ], `+ J- l8 M) ~) g: ^( G  {     
8 c2 B1 K5 {% W& D  if ((email.charAt(i) == "@") & (email.length > 5))       p9 W9 C8 x  h6 h5 L3 y2 ^2 r
   {     ; Z6 |5 }3 S- p8 S: y
     emailerr=emailerr+1     
5 ?( c6 |8 `: x5 n4 d   }     9 l* N% a' C- c- S3 C
  }     6 v) ]* H' q2 U" P* ^; i, q0 s: ^0 {
if (emailerr != 1)     9 C# I) t& R% I% Y4 \5 B, E. H
  {     0 Y, j5 C& A& h* J
  alert("请输入正确的E-MAIL地址");     . m! k- U: v5 a$ ~4 L/ V# }( x
  document.sform1.email.focus();     ( T  o1 F* S- E- ~/ b/ N
  return false;     2 S) L+ K7 [7 [9 j
  }           / L8 v7 @5 t" _  Z( O3 [
  : U: u9 e9 A/ T# w$ ~
if (document.sform1.checkask.value=="")
* F- R. Z/ F2 ]. D( A- W% I  { ' q6 M5 z* {+ e' p" R1 R
   alert("密码提示问题不能为空");     
: x4 c6 \. a! p! t1 w- V9 }   document.sform1.checkask.focus();     
1 o0 ]/ i" r1 F' M$ v! {   return false;  
. Y; q# I/ {  z0 a' o. ?  } % S# y4 e5 `& ^( S
if (document.sform1.checkans.value=="") 7 W2 N% T$ F( h( o( a4 c1 E7 ?
  {
6 t$ Q) o6 v5 w- C   alert("您的密码提示问题答案不能为空"); / k3 v/ m; W7 I- K/ n6 h0 Z
   document.sform1.checkans.focus();     
3 O# Z6 z1 {% M8 L6 u   return false;  
: ^* w; j5 z1 d  }
& E# B# l8 }' F  F/ ]8 s: c return true;     
# p) f7 _6 K1 F9 y$ Q6 S& R1 P  X     
, G8 m& N( ~$ }6 R/ h0 k1 N}
7 {/ P7 f% D! ~* k</script>

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