返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
2 r# A$ G: a9 [1 D<script language="javascript">     # m' T# n+ ~6 o9 o
function IsDigit(cCheck)     
; i1 k  S# a" D- r) L- q* s {     7 @7 N9 i6 `- `! N* j; q! {1 T; }1 P
return (('0'<=cCheck) && (cCheck<='9'));     0 d  `5 [' E3 C! @, ~3 \
}     ; U3 i2 H3 {6 H) {
     
4 T" L: F- M, P0 o  [6 Qfunction IsAlpha(cCheck)     
- Z6 o6 I( Z: V/ {2 ] {     
) x+ o+ f% O; t/ E6 N7 }- Q3 P5 N1 V return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     $ w1 l- p7 y( M, s
}              / [. m. ~9 B. V+ \/ ]
      ; \1 j/ j9 M2 w
function IsaNull(cCheck)         
3 F+ A, z" r9 ^5 [$ m {          - o6 T* z5 i) m* I6 \6 q6 Q- i1 `2 Q
return(cCheck != " ")         
* i7 t  ]5 [( S' _6 E }                               ' }9 R' ^' w9 ~$ U9 t: y9 y
      ' C* Y$ R' {- i
function checkform()     ( t8 Y4 b& q. P0 }: K+ F9 T
{
' G3 P( W0 x9 y3 i7 q  id = document.sform1.id.value;     
6 R( M7 i$ h" K. X- I  H$ v0 R# P2 Q if (id == "")     
# ~6 @2 Y3 K' A, d" ~  {     # X: `5 n2 i( K7 H- e0 \/ o: c* [3 w' A
  alert("请输入注册名");     
* i7 |1 D1 c+ V$ |" T  document.sform1.id.focus();     
' U! z- X& A: |7 ^  return false;     
* ^* y0 I0 V' ~: M/ r( {  }     9 Q; j( t- h* r  k* i
     2 |$ g# Z" z( G* d6 A7 G
for (nIndex=0; nIndex<id.length; nIndex++)     
/ N' d9 Q% A+ ], d9 e  {     8 `6 R$ r: A2 n$ ?  X7 G
  cCheck = id.charAt(nIndex);     0 {. U8 l* h7 ], D3 k% c; P
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     # ]5 i6 U. A, Z( w! H: m% A) R
   {     
$ L$ V  j4 a/ F0 j8 G+ N5 h+ M   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     . F% C( I& I/ N+ H% l. b
   document.sform1.id.focus();     * X/ l0 f, }" U$ I' S
   return false;     # v  H; p* X2 F5 W. ~
   }     
% Z- S6 f* W2 J0 I0 w* _, o. R  }
& I6 w( D0 P# Y7 S6 X' u, h7 A  chineseid = document.sform1.chineseid.value;     & p3 d9 K  T6 q' s" n
if (chineseid == "")     + H% I1 t9 E6 ^! F3 q
  {     
+ n0 ^0 {" \7 I# Q3 k7 P* C  alert("请输入中文昵称");     
$ n+ g8 V9 d' L6 H$ k. X1 I% D& x# u  document.sform1.chineseid.focus();     
# {3 M: K/ L1 k3 i7 F  return false;     
- N& C, Z+ T$ {  }    3 l. s2 O2 |. C8 C) h& ^& t! I
password = document.sform1.password.value;     
: Q/ Q" J6 s: h# y( m: z if (password == "")     
! l3 ^# z: A" _  {     
5 `8 S9 Z0 [7 q* D7 f' [# L+ U3 b  alert("请输入登陆密码");     
! Y/ @$ o& e( c& ?6 F  document.sform1.password.focus();     3 C& h) Q5 ~3 f9 L/ K
  return false;     - x) J2 ~5 M; J6 j
  }
( {) S' j" ?8 `6 L- }- j password1 = document.sform1.password1.value;     5 {% n; I7 M" ?4 }5 N" i
if (password>password1)     - R4 ^0 m& i  c1 L4 z5 o
  {
1 q- r5 i0 j/ x     alert("重复密码与登陆密码不相同");     + [8 D) V, u8 k7 r+ }0 @! V
  document.sform1.password.focus();
2 b  r$ t3 a' ^% ]. e! J                                document.sform1.password1.focus();     
3 Z  c: e( L6 n  return false;
/ J. \. b9 t$ p) O  }  + ]5 Z+ [8 i' s6 B, `% W! \
if (password<password1)     6 X4 ?: i& A$ k( w4 J
  {
+ g& T* I9 _: L, Z3 i     alert("重复密码与登陆密码不相同");     
( l, M# C, @9 n  x0 f1 x4 c  document.sform1.password.focus();
2 `# A0 [9 D" ?                                document.sform1.password1.focus();     ) B! Q5 D. p* W* o0 B3 Q0 q9 E
  return false;
9 f( S6 ]2 x7 H/ G& G  } $ j" l$ t5 O! i
if (document.sform1.email.value == "")     
2 K1 m& @0 F+ `. z: z. C  {     
: W8 i  @# d8 A, z! g+ M$ k7 ?  alert("请输入您的E-MAIL地址");     9 B' D0 }0 Z9 I, b
  document.sform1.email.focus();     
3 A- N* {$ l. w- y# A/ n/ E- V  return false;     $ a, p6 s1 }* _$ j
  }     
& |, X' g' ?% Q+ K5 u      5 w6 M: F8 d' M/ r9 t3 E  A+ B) }
email=document.sform1.email.value;      
$ d9 \, I4 r; r4 f8 n emailerr=0     9 m0 A1 O# G* p) ?6 C2 N! y
for (i=0; i<email.length; i++)     
+ w6 y0 O9 E" T  {     
: K4 O4 g5 s, }. c; j+ S  if ((email.charAt(i) == "@") & (email.length > 5))     
1 K( l0 h/ E* Q/ z   {     $ S% q8 k$ A% }9 k: O7 o
     emailerr=emailerr+1     ! O4 `8 i1 g) \) a
   }     3 l) |) R2 \3 V' X  e
  }     
1 k# b& ^1 e0 D! x2 {5 c if (emailerr != 1)     3 O# G5 Q" C4 U, @: t1 Y5 O) ]
  {     * ~% T& }# C! {
  alert("请输入正确的E-MAIL地址");     
0 q# B4 E$ t4 E0 i, g% n; g4 m, o  document.sform1.email.focus();     
" P! ^; p& p! o7 f$ H1 S8 y  return false;     " j) `8 R4 w0 E6 p2 B* u
  }           ; e: I+ f- R) |$ a
  
/ _' _  I' z% K% M if (document.sform1.checkask.value=="") 0 ]3 c" ^; l! {- k9 Q4 z
  { ' z) V$ C+ E; w$ r: C* G
   alert("密码提示问题不能为空");     
0 z9 N; q$ B  ]' M   document.sform1.checkask.focus();     
* v7 Z3 _& ^  H5 [9 E   return false;  5 E; P# c( P* H$ U" `
  } ) i9 I- n8 c; Q
if (document.sform1.checkans.value=="")
$ e4 v, z' l5 @  { # ~- @/ z8 n3 d7 ^# ]4 ~9 C
   alert("您的密码提示问题答案不能为空");
! k# D$ C+ N0 M  y   document.sform1.checkans.focus();     6 @* T" B8 T9 R
   return false;  ; G( ]% F* J# G
  }
/ S0 K9 b& G9 u2 q8 q( z, `8 ^ return true;     
) i3 `6 v  A; }6 M9 v+ j9 o* M5 D0 _     
4 j' t' I0 p; V} % C' x8 @* F; K6 c( ~: e
</script>

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