返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:. D- H4 q5 l' v, Y! v& M4 X
<script language="javascript">     ! X. }, j6 s) A& ?* D/ b
function IsDigit(cCheck)     
8 U- O3 O- F; k2 v {     ; F9 _- {/ D8 i1 N
return (('0'<=cCheck) && (cCheck<='9'));     + t! _7 a* e) _' a' ?
}     
! J0 Y, l0 a7 h# C6 Q     
* g; p; g0 V8 l3 sfunction IsAlpha(cCheck)     6 Q3 @" [# ^2 s7 j' A/ u
{     4 l( S- U; B$ {2 q$ G
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
% l0 k/ C% ^  f3 I }              
7 ]* r; w- B4 z8 z- u7 }      1 S4 ^! A) ]2 r; ^
function IsaNull(cCheck)          ! X. o7 Q% K9 r
{         
- s' V& i9 h- ^; O- V8 p! S return(cCheck != " ")         
8 v" L/ `  Z& s/ c }                               + s$ D* C! t; u, ~. g$ d
      ) N2 J' Z+ B! l& ?" r4 Y2 v8 [
function checkform()     1 e) h6 w6 M( F, d6 e
{   Y- W; `9 D5 _  @" r
  id = document.sform1.id.value;     ( D0 Q2 `3 Z8 i; U& L" F! F
if (id == "")     8 E2 l0 G7 O7 h7 o, x: J
  {     ( e/ a; l* d  H, O. V
  alert("请输入注册名");     
- y/ t! c/ s& U' ?  document.sform1.id.focus();     : n- E3 k+ V+ H* K0 W6 x; w; L. e
  return false;     
3 p1 H3 U6 d, h* k( O' g5 p1 f3 ~$ B  }     
  z7 P( M  X6 ^- g' ^4 c     * Y/ E1 ?& H! m1 ~2 y
for (nIndex=0; nIndex<id.length; nIndex++)     
; m$ G  B7 m' d6 Z8 a5 Z7 M; Q$ V  {     
  {$ a0 w( d9 I% K7 z  cCheck = id.charAt(nIndex);     
* i( }+ X; j* r2 L  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
  O3 X" N4 o2 ?( p* q   {     
7 v5 _7 k% K4 \2 I, R# p0 Q   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
8 j; `6 T! e2 G$ V7 P   document.sform1.id.focus();     
' T( a1 h1 U: \* J; s/ x   return false;     6 Y1 M  {$ c  Z- t4 ~& D2 T% Y* y' ^* n
   }     
; W' w/ S' L! u1 V8 Y2 ?  }
4 u0 N1 \. M. u, x  chineseid = document.sform1.chineseid.value;     
  t) ^) d. N9 q* r9 J: Z if (chineseid == "")     ' F" x0 K; a8 k
  {     
/ N+ X2 m  c( @0 F& Y5 e5 M3 O  alert("请输入中文昵称");     " _9 A! e* |/ j2 i
  document.sform1.chineseid.focus();     
0 T3 E/ D9 [' a$ r3 D  return false;     
- O/ e! M/ t7 ^% Y  E8 c  }   
7 u, i! S4 u) b  Q password = document.sform1.password.value;     
% L1 ~# P6 S+ ^# m$ q5 Y0 m6 G if (password == "")     6 p& r9 x- J# C2 Y- z. Q" t3 g, N
  {     
! _. B; T* G# m7 v$ R9 v, R7 Y  alert("请输入登陆密码");     4 p1 f: N2 o5 u$ W( r) ?6 B! r- q% J
  document.sform1.password.focus();     . X% J0 @. B; t" b
  return false;     " W; ~* F, x# V! E) I  c
  } 0 z; s4 W4 ^! y7 i+ }6 `0 W" ^
password1 = document.sform1.password1.value;     0 w5 I- _) v( ]8 R( C
if (password>password1)     1 g7 S" F. a0 ~
  {/ q. I  _3 n9 c+ ]7 h9 I' r4 i
     alert("重复密码与登陆密码不相同");     / |- D- {1 u' e; g3 J
  document.sform1.password.focus(); , {8 j3 }4 u& G  c) n  ^/ ]* p4 y
                                document.sform1.password1.focus();     + _/ b: ?, Z2 t, E' p/ }& T! _
  return false;$ Z: \4 G' p+ X
  }  
# B0 M0 d8 R! H8 g6 T* \8 Cif (password<password1)     
. O+ o9 C5 d! }: r% B: F  {
. z5 {/ l" ?. g6 E( _     alert("重复密码与登陆密码不相同");     2 i2 `! ]0 `1 y- O; l0 t5 }* e
  document.sform1.password.focus(); % H# V1 A  G& i, R. u, o, r( u- ~
                                document.sform1.password1.focus();     & F$ Q9 K  E+ P# |, S
  return false;
1 M% o9 ]2 T' U8 ?; `' P  } ; t: S  }# V7 L8 R
if (document.sform1.email.value == "")     
: u" [0 Z2 d( V5 G0 \  s! p  {     / p& T9 e! O$ z9 g
  alert("请输入您的E-MAIL地址");     
  @' B! ?8 n) M  document.sform1.email.focus();     
/ I' b$ Q" t6 Q5 @# o  return false;     
2 d6 M/ C, ~8 ^! A9 Y/ |  }     ' ?4 J' d7 P5 `# C
      * ^1 h  B1 T- _! L
email=document.sform1.email.value;      
( ]- E/ w* B5 x: S6 y emailerr=0     
4 U/ J5 O8 F, n7 l$ o7 @) w for (i=0; i<email.length; i++)     0 x& e; Y8 g8 [# v0 l) {5 g
  {     
& Q0 D4 V. n1 Z! j6 x  if ((email.charAt(i) == "@") & (email.length > 5))     0 N; x! h! C, y3 s
   {     
  Q* f3 h5 |3 B/ m3 I     emailerr=emailerr+1     
7 ]2 h/ p! y; S% l: l2 R   }     ) b- q9 Z* b- ^3 q
  }     
6 Q/ H+ ?1 ~* G$ ` if (emailerr != 1)     + ]. A$ m" I. G9 n" U) i
  {     2 T; t' c4 w) y! J7 C
  alert("请输入正确的E-MAIL地址");     3 N  O' C& Z- h( ~1 n: H
  document.sform1.email.focus();     
3 G1 M' m! S) r/ U# g6 _$ n/ `! k  return false;     " ~8 E6 ]2 h. |$ x4 {7 Z' [. T# C
  }           
% q7 I0 [% x; L2 ^' l. E5 Z0 h  * T' Z( p/ u+ P
if (document.sform1.checkask.value=="")
+ k: K2 Y9 w# w% B5 Q2 b* C1 I  {
1 B' Q3 V1 f$ e& p   alert("密码提示问题不能为空");     
/ U4 g* Q7 _( l1 ^1 S7 y& s5 w% U   document.sform1.checkask.focus();     1 z. o5 J0 b# O, f- Z3 ]' b
   return false;  * f/ f; K0 v4 H0 Q5 _* R6 ^
  } 2 k9 y" w5 u6 u' P
if (document.sform1.checkans.value=="") $ k5 H2 D5 r, P* X% R5 {9 d
  {
. z- s; R( `  E" g3 [: b2 m   alert("您的密码提示问题答案不能为空"); : X8 P& R/ s: a; f
   document.sform1.checkans.focus();     . t# c( N: S! ]  W& C% {
   return false;  1 P, F/ P9 s: v/ X' K  [
  }. I; s- s) P/ |% T8 m% Q
return true;     
8 @2 R( y' H5 V4 I; u     
' y7 x) f; K9 L- Y# m' }} 9 s& q  B1 S! {; S7 A7 [6 k# g
</script>

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