返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
" q$ k7 W3 j2 A! q" c<script language="javascript">     
4 ?6 ?8 d  f$ d# k: v7 M* [" dfunction IsDigit(cCheck)     7 t* s" @7 K9 B1 D" M4 L$ l/ \
{     $ ?% ^# M$ T; t' L% \
return (('0'<=cCheck) && (cCheck<='9'));     + x0 ?! b+ Z+ e
}     
$ K4 P  ^' n4 u; ?, N     ( w* x! H) ^; x" t
function IsAlpha(cCheck)     
5 k+ _2 x5 n3 [4 { {     
+ H( E0 ?* m* O return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     8 m' t' V( f$ t+ K
}              9 e3 I8 j; S+ `5 f. Q1 W" E% E! a. G
      
& c# |& m* m* y9 ~4 L' n: sfunction IsaNull(cCheck)          9 V2 u( k% O' I- V% \
{          : x% O: t0 {- g
return(cCheck != " ")         ' I( Y* N& ^1 [; ?0 G4 R/ M
}                               , ?* p7 U/ @; y& R7 V- K
      - d3 \; }% L3 S/ L& l) D9 z' E
function checkform()     
9 V! U, G( t8 j  {{
7 c" c. y1 W# n" M/ i8 S  id = document.sform1.id.value;     
, `2 Y$ c/ t" S( e1 f( J4 ~ if (id == "")     
8 d3 ~7 `. o& F+ ~6 S6 m8 q  {       c. g! s$ P5 }& p" Q" ~, _
  alert("请输入注册名");     $ s# e, c0 r3 k
  document.sform1.id.focus();     ( }" u- o# w. r1 n2 V4 O4 D# ?
  return false;     
( k* z3 |6 |4 s3 ]$ e2 o4 `  }     3 T* L; L' J- i8 n2 E: b
     
& W2 g& O$ g2 P4 h/ \* S; j9 E+ f for (nIndex=0; nIndex<id.length; nIndex++)     0 n7 B4 N2 S- I8 n4 h
  {     
* z  a9 k. l( ]  cCheck = id.charAt(nIndex);     ) B! x7 ?- H0 X6 K( W- M
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     5 o  e5 Z: N3 r2 L9 M3 F' _
   {     $ ~8 M; x- s" f$ ]- Y
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
1 I/ }# A; X" V: U' ^, t( X5 H   document.sform1.id.focus();     
! I0 f' N. E( f3 s+ z) l   return false;     
+ Y$ U2 n& X  u6 z" m7 I. u9 r! C   }     / l8 K# I1 U2 j5 Y
  } 6 [: _& P! U) Q7 o  N
  chineseid = document.sform1.chineseid.value;     * O1 s2 p- a1 Q6 E/ n
if (chineseid == "")     
5 V  `8 E- {! J0 i5 T  {     
5 Z( ?% o3 ^  U  alert("请输入中文昵称");     
- ^0 `) {, d" r! Q8 M  document.sform1.chineseid.focus();     
! a+ S0 H" c- @- S  p4 t  return false;     " q" q  h* m2 O; W
  }   
. R3 M, K1 s' g password = document.sform1.password.value;     ; s& y8 S& `" G, E
if (password == "")     , }, e( W, q+ E; y. L6 R, X& L5 i
  {     
; `2 ?: c/ T# H5 K8 _8 K( Q  alert("请输入登陆密码");     
" i! X) A! p+ i  h7 b8 o: K% t* h  document.sform1.password.focus();     . H- c# @3 T- I: \
  return false;     
8 w9 I- R! j/ `7 K" B# v2 w  }
. B, @, X" R  Q! Z password1 = document.sform1.password1.value;     
4 w" t# }6 [  |' |2 U8 ~. I if (password>password1)     
+ U7 j$ c, w3 i  {! O& ?' k, e$ J! e# |2 ~
     alert("重复密码与登陆密码不相同");     2 a. W7 w4 I5 t& A
  document.sform1.password.focus();
3 ^0 G4 G4 o9 T/ u: t! e2 {                                document.sform1.password1.focus();     
/ {1 ]" b7 e5 S3 ]( C" N$ W, u  return false;
1 o  J( p6 p9 y! O' b  }  5 ^, p' [. p) G# X; n
if (password<password1)     ' T4 f% p0 [  Z$ P
  {4 M' e7 M: y: e
     alert("重复密码与登陆密码不相同");       g& t9 r. V# N0 c" W& B' g
  document.sform1.password.focus();
7 S; w8 p; g/ i2 k" E                                document.sform1.password1.focus();     
, i. @5 u( }% d9 C% x' x  return false;
* @  _- c( o/ ^5 }  }
1 T' r' W4 X( p' y if (document.sform1.email.value == "")     0 E& b* \, Y4 L4 [+ d. e: D9 F
  {     1 m$ g( m! t/ o' ~% ~5 h- ~
  alert("请输入您的E-MAIL地址");     
$ p- u% o" l/ Q9 z- L9 {) Z  document.sform1.email.focus();     ' ]" s, x, \! s: x
  return false;     
% P8 o' e( Z( l/ j" }8 a3 I5 v- R  }     ; L- l) e, v) f3 N8 Z
      
- H  F4 O/ z" v; A: x, R9 f  @ email=document.sform1.email.value;      
, L- _( w/ i. X9 G3 \ emailerr=0     # v, J* U) Z" y& R
for (i=0; i<email.length; i++)     : C! Y. o' C& c% V6 n2 y
  {     & N5 P& I0 w, p3 a+ S) y  ^; d/ c
  if ((email.charAt(i) == "@") & (email.length > 5))     
  O4 _& H- m+ t4 F& a# X4 w   {     
1 w: p5 \$ Q0 R1 S, v     emailerr=emailerr+1     
1 O# [3 m9 G: n   }     
+ D% ]/ L. M$ c: c+ y+ `  }     1 X* f: i& Q; n/ }. e: R& O7 x4 S+ l
if (emailerr != 1)     4 T, c! B& ^! I4 i2 P
  {     
3 h3 f- Z/ `5 Y: r0 T  alert("请输入正确的E-MAIL地址");     ; N1 |3 Q1 m/ B$ \2 L2 n
  document.sform1.email.focus();     
1 |( V( J2 B& ~: i0 K% U' f1 g, Z  return false;     2 \0 B9 H8 |! {' J" z- w8 |( o
  }           3 b% O) J* k6 x& K+ S$ {+ Z
  
" R) ?( j7 G, C if (document.sform1.checkask.value=="")
8 t9 N; r) ^; V2 X( E3 g( `- B  { " _- G9 G! W2 t' h/ s7 D
   alert("密码提示问题不能为空");     ; @  M2 x  t9 \
   document.sform1.checkask.focus();     % h2 }* m0 N. k, a5 W
   return false;  " c* x) W9 w# ^* T  B6 r+ T
  } & ?0 |- R5 c( a1 U4 M( x
if (document.sform1.checkans.value=="") + z& a8 S! @  n4 I. O8 {( _9 Q
  {
- b& r8 |/ F4 W. y   alert("您的密码提示问题答案不能为空");
7 ^& `( K, S4 z   document.sform1.checkans.focus();     , M' f* t) n' t9 Q7 c
   return false;  
" t5 O) t* x. w  b, A9 R  }
) }$ _7 t8 a/ H1 T7 \ return true;     & C# i9 _+ t  C# ^% }  c) _
     
9 @) c2 Q% E  ?) F8 D! ~} 2 @" E8 E6 F$ F( x: _* X1 F
</script>

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