获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:/ H  p! v4 k- G7 }
<script language="javascript">     
' g8 `% U7 d5 F: [function IsDigit(cCheck)     % p, n: j6 S% G* t' l3 }3 g6 E
{     0 Y3 f& t0 T" [! h
return (('0'<=cCheck) && (cCheck<='9'));     
9 ?$ K7 ?( }% g" O# ~ }     
6 v3 R; u0 X; B4 B     
0 r' l' ?# V/ ifunction IsAlpha(cCheck)     6 }0 A: x3 {# \
{     
8 }$ L" ~2 ?( u+ s return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     1 Y2 h0 {3 g. Q" j9 f9 S
}              
  P$ P# L, m( S6 d+ ?9 M9 d) X      
# q5 e0 v0 N0 C4 E! A) Kfunction IsaNull(cCheck)         
% H7 X! r* b6 Z3 z" J% T# D4 Y" w {         
8 u2 Q/ L3 A( _$ c0 J return(cCheck != " ")         
8 k6 @) a' S$ l }                               2 e" w+ m+ m9 \1 H$ j1 S& Y
      
/ z" i* l3 z5 Vfunction checkform()     
) H$ Z# g, L4 U7 U/ }2 {& Q7 z{
) W* E5 Q& X2 s5 t" A  id = document.sform1.id.value;     0 D& u  X1 |' H  y
if (id == "")     ; M; p" h. Q6 ]( o! j) c# X
  {     
8 G" [' E) N2 f% N9 j! ]7 j  alert("请输入注册名");     
1 K9 V" ^. P! U) f4 w& `  document.sform1.id.focus();     , u$ T4 s. d8 n6 H  g
  return false;     
" k4 H# W4 R, T) Y+ o$ |  }     
7 A% Y. {. b4 i     
' k' T. t0 b8 T* f$ W for (nIndex=0; nIndex<id.length; nIndex++)     
/ ]* a. S) }4 [( n. t  {     7 D6 D5 {% {, C) X& R
  cCheck = id.charAt(nIndex);     
6 H: D: V. Y& E- L5 U  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     : k$ h% u  D# y; P/ `6 w
   {     
; ~8 X+ Q  L4 c  \9 n0 H3 ~- F2 ]   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     + W8 N, {$ z: D7 ?
   document.sform1.id.focus();     
( a1 r0 h' K# z! l/ d   return false;     
, q& n( ?! F! a& T4 }1 A   }     / V1 O; s& @+ s8 j1 }  a! N
  }
/ ]3 B* L, k& G' l0 o* M$ t# ?+ M- Q  chineseid = document.sform1.chineseid.value;     
- I& `+ {% X4 q- ~- X if (chineseid == "")     9 k* g2 I8 L' S  b, {  r
  {     $ d) m5 l7 }9 x, x# K
  alert("请输入中文昵称");     
+ |8 h: q" ]! I; Y+ O5 @  document.sform1.chineseid.focus();     ' Z; g9 S; n3 s4 x0 x. h
  return false;       o/ t9 L9 O, \
  }   
6 y: Y9 ~/ v, K1 h0 ` password = document.sform1.password.value;     ' m( K' C6 `1 {) ^- G
if (password == "")     
: p# B! m& P; K  {     % T3 y* w/ x( f0 P# Q
  alert("请输入登陆密码");     
( ~7 w* F8 F4 a5 w  document.sform1.password.focus();     
4 A2 ^. C* k% x" G: u/ q- B  return false;     
8 ^  d5 d  ?5 S, b( ~4 _( W7 f4 S  }
$ S( \/ j* q( d/ W6 G1 J/ V. `  w password1 = document.sform1.password1.value;     
& W+ L, d, n; o  I, e5 i if (password>password1)     & y4 n+ _( v& a
  {4 Q. |( o, ]9 q0 Z+ `: R1 w
     alert("重复密码与登陆密码不相同");     2 i# F% k% l2 I+ U/ V
  document.sform1.password.focus();
) X9 u" O" I  ~. |                                document.sform1.password1.focus();     
. J" i4 y# @9 n3 t' B* l5 m  return false;+ t1 b. u& r- ]3 z" p
  }  ; V# {1 G: \( T
if (password<password1)     
" F6 N2 ~; X. O, _0 s  @. V  {
! W% l/ }- t1 U9 _/ G     alert("重复密码与登陆密码不相同");     
3 D0 \( G8 U) l; ]  document.sform1.password.focus();
* B9 }) c; k' i5 f0 o* Z7 Z* ?9 {                                document.sform1.password1.focus();     / ^+ R; f+ n# s8 C5 x
  return false;
$ T! j  p! o5 t  } ! N$ N) C1 A, S! a! V, b
if (document.sform1.email.value == "")     
6 j% N1 n. m$ ]  {     
4 m) ~3 O  l" S- Z  alert("请输入您的E-MAIL地址");     
% i3 w8 w* B$ T+ ^' _( M  document.sform1.email.focus();     
1 t0 c0 c% j& @6 j+ W  T( A' b  return false;     % G4 c5 V5 e- N
  }     : ~6 [6 c! V1 K  W: r  W
      
) y) q9 a7 ~: x) W email=document.sform1.email.value;      6 E; s7 Z) {  d2 y5 w% u: W
emailerr=0     5 M. s+ t: c. X$ ?, w; o. G
for (i=0; i<email.length; i++)     
6 y* Q6 o5 u) }" E: P  {     + P2 L8 V+ Y3 Z; Z
  if ((email.charAt(i) == "@") & (email.length > 5))     / ?* t: x- S! D+ u& y
   {     6 x, y- N" Z& G* o: c; a9 i
     emailerr=emailerr+1     
" X: M$ S" K; c% f   }     ) Y5 i2 q1 \. @2 Y+ C6 j+ \) a
  }     4 Q9 F# t. W+ \& c
if (emailerr != 1)     5 c! R* j6 F7 Q# n. t$ _3 g$ b
  {     
: t: K+ u9 d* k' a0 t6 y3 h, b  alert("请输入正确的E-MAIL地址");     / v6 a4 u, ?% N, G  U  m4 `
  document.sform1.email.focus();     ! C* b" I* q) Y: f6 N/ e3 w
  return false;     . {% B1 y( Z% T/ F* p  R
  }           
( ]2 v4 q3 S2 U# r8 R; p  , D! m' `0 `& r4 [3 S* e+ d4 Q
if (document.sform1.checkask.value=="")
# V5 ~& |. x8 }- W$ i+ G  {
) Q* V6 w3 ^4 Z3 T9 J9 V7 a   alert("密码提示问题不能为空");     % `& S" D( `4 `6 F8 B2 C* K
   document.sform1.checkask.focus();     
1 B( Q" V  b% M   return false;  
; u2 D! }" h4 V- |3 K* l  } 8 z7 e" L' h" z; d
if (document.sform1.checkans.value=="")
0 ]1 [$ A$ ~& J$ Y+ y+ t; k3 Q2 o. N" `  {
4 [& E/ w9 a/ t4 v+ V   alert("您的密码提示问题答案不能为空");   E! T3 Q" V* W. l
   document.sform1.checkans.focus();     % d2 v: r! w' [0 W
   return false;  ) p7 |4 c. K1 g3 r7 v" I9 S* Q
  }1 y* {3 H6 r8 I! J% L& K* l
return true;     ! `1 P( f  J% O+ Q7 q. j
     
. H7 G4 K, J/ J( n} : F. V' x+ _# c+ g* t! {6 n9 P+ `
</script>

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