返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
8 f4 s# \' H/ f<script language="javascript">     9 U; J; n8 p( b6 h
function IsDigit(cCheck)     
9 K4 \8 t4 L7 u  D% b8 j7 W7 F9 t {     
( B& \; g7 k5 Q/ a6 {: @, u& s return (('0'<=cCheck) && (cCheck<='9'));     
6 o0 ]! N; |* q% x# t0 S% O }     
) }2 u7 J1 c$ F1 m6 J) E     6 G+ t- ~" I# a" {0 U6 D0 X; q
function IsAlpha(cCheck)     / b. Z/ ^  V& _0 [' T/ _! h' n  w
{     4 O$ U& }' i3 l
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     . P; A; g3 c$ c& a) _( v5 x; h
}              - R6 X6 U+ l0 ?5 r6 r6 R* n8 G& ]
      3 t  Y: r1 ]: n. V3 b
function IsaNull(cCheck)         
- Y) r, ]4 B! { {          ' ^+ \3 x# ?8 z! _& H, t6 n& _
return(cCheck != " ")         8 T$ ]- k; P5 m
}                              
( M! v8 B+ [  {% p$ C4 R& H      - I+ C1 a( J/ T/ l+ R2 Q4 R
function checkform()     4 G' o3 E. T( g4 a
{
) p! G% C9 w: B8 \2 a- b: E4 i  id = document.sform1.id.value;     
+ c5 t2 A" Q4 h' e8 k if (id == "")     ) E1 Q) l. D* g4 ?6 V
  {     
2 t3 V' T9 W  U) _: O6 i5 ^  alert("请输入注册名");     1 r0 U' l. G; u; A
  document.sform1.id.focus();     . B% B: g2 \, u
  return false;     
$ n" Y; \. m. v0 W% Y2 \  }     * _1 x/ {+ D! E# _& _$ d
     
; W6 t$ P8 d. H/ y9 X for (nIndex=0; nIndex<id.length; nIndex++)     
: S1 g9 s' y, T6 l" g2 B  {     0 f% C; v, W1 i: z: s
  cCheck = id.charAt(nIndex);     
  ?8 B% w4 r* l- [/ @  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     & @  R1 V  a3 F$ a  J( ~: j* I% k9 u7 H
   {     7 l2 n- q  X- J& A
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     8 L/ ^1 C0 u. D& q
   document.sform1.id.focus();     
, I8 L0 x5 _) `& O   return false;     * t6 V2 m1 n0 s/ o, G% M; t
   }       P$ d" i0 z$ x4 ]6 {, ^
  }
/ a' T5 D2 [: w0 k, l  chineseid = document.sform1.chineseid.value;     7 y0 B8 T& A% [' N7 O$ h
if (chineseid == "")     6 Y3 S! V4 @' a  D% z& @& H
  {     8 l' C! G, A  P" ?: U
  alert("请输入中文昵称");     & p$ H! L3 I, b' x
  document.sform1.chineseid.focus();     7 e, B; d9 z' x+ g. _
  return false;     
0 f) c& w5 w- j8 Y. D! N! n  }   
. K+ |; L5 h! O% u7 U+ R password = document.sform1.password.value;     
* h, s4 M9 y2 Q! M if (password == "")     2 }4 R' K6 |7 @! d% X' q  L" x
  {     ' M3 T" A  O% h8 y
  alert("请输入登陆密码");     % n3 m* H0 c% C* ?: h* t/ J4 a
  document.sform1.password.focus();     $ S# i5 y! n; T% N  W+ ~3 J
  return false;     
2 \+ N' m2 z) A* ]  }
* c- p8 y2 T4 q, b password1 = document.sform1.password1.value;     
. V8 J3 s) o; |% j! ~ if (password>password1)     
" k- B3 S6 ?* W, j0 C% K# J  {
! J1 W5 M* j' V6 T' ~" O) \     alert("重复密码与登陆密码不相同");     
( b: W% h+ z  D' `7 ~  document.sform1.password.focus();
+ ]4 z9 U0 t* C8 z0 W! E& h  y3 a                                document.sform1.password1.focus();     & F+ m& S- h4 `7 s3 v* Y; t/ f7 H! i
  return false;( g8 u5 ~5 |+ x4 `
  }  
  p- G/ w* `, H- c2 D* C1 Aif (password<password1)     
" _; q& I1 _3 G  m* L) l: @: b  {
- i# s" p3 i, h2 d. E3 D* N9 z3 [. u) i     alert("重复密码与登陆密码不相同");     
+ |. F* r) P7 S  document.sform1.password.focus();
9 Q: A1 A8 t1 S                                document.sform1.password1.focus();     
' w+ W. X5 t. Z! _5 U  return false;
! L. r$ w; b5 c! l, H  }
2 j; S7 d+ L' \5 f7 a if (document.sform1.email.value == "")     
3 W7 j3 u( c3 w  {     
, G1 q& U8 p! |3 A" H  alert("请输入您的E-MAIL地址");     
# K! v4 T8 ^# |+ d2 e  h  document.sform1.email.focus();     
( L1 l. y' e, @( v  return false;     
/ n& i3 ~9 c- _2 Y, C9 l- L  }     3 J/ v- A9 ^3 \1 D4 w4 t1 F  U
      , k3 |, a5 Y6 s& ^/ |" c
email=document.sform1.email.value;      
0 J' w% T; k8 Q& z. h) F' ` emailerr=0     ; p- A( b; O1 ^
for (i=0; i<email.length; i++)     
9 U. n4 h: E& D: g0 A  d' Z  {     2 d, z: t9 z+ d: v
  if ((email.charAt(i) == "@") & (email.length > 5))     / O2 l- ~; I5 a! V. B1 ^
   {     , u' g! P( p. J9 \
     emailerr=emailerr+1     5 o" z) J3 E, D5 j1 _3 I4 ]
   }     
( q% y! A% ?/ W8 Y" L, b  }     , ~4 d( O0 `. i, M1 B" x" E
if (emailerr != 1)     + ^8 t% s- Q8 z) [- N
  {     
7 A" Q$ N1 P  f9 e  alert("请输入正确的E-MAIL地址");     7 L) }- @0 h: p" x
  document.sform1.email.focus();     8 W1 u. K3 w8 T) z
  return false;     " g0 D1 B4 ~% f& y1 o
  }           4 Z$ h5 S' @" e0 y0 x
  7 x3 {0 E' F' L& t
if (document.sform1.checkask.value=="") 3 l$ R) p' u# A* P% |
  {
; \; B, O; X6 x. c+ D   alert("密码提示问题不能为空");     $ G  f* H1 V- t4 I! |  u! r
   document.sform1.checkask.focus();     
7 {/ c$ u1 O- r4 C; N   return false;  , ~% U# B$ Y) L( \( Q
  }
* n; E9 a' |7 |4 J2 Z, ^) z if (document.sform1.checkans.value=="")
7 B/ b& C$ \6 p  { * A2 U; W" y; Z! I0 V
   alert("您的密码提示问题答案不能为空"); % {" O: v3 L8 R" _" r# ^
   document.sform1.checkans.focus();     5 B+ P  y) Q# Y
   return false;  
% k! @9 n6 D% {4 M" E  }/ p4 C5 p9 y# V! B+ [  t4 J
return true;     9 i) i6 Q/ f2 w7 \' A
     0 y6 r5 H- c& s- Z' S9 G3 f
} 3 G0 q( M7 O" o2 R
</script>

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