返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:2 w; D! U9 b# y& l# z2 w; \
<script language="javascript">     8 z8 @- S1 j4 y# \
function IsDigit(cCheck)     
, p6 \$ y' e* c {     
5 m7 C: d" m& S8 J2 `$ ? return (('0'<=cCheck) && (cCheck<='9'));     + q9 T4 v* M% d  K3 p( n$ w
}     
& e1 p0 r& c4 m5 V9 Q) C- r     
" f4 M! q; h) W) u% Sfunction IsAlpha(cCheck)       t: y$ x* E5 Q  C4 |- p6 s# l
{     
2 F- M1 X# B) t' `4 G9 S8 c- y9 e2 @$ ` return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     # l& Y8 v' J  s) i: a- n% r
}              
, |* X7 }, h& }( q      
8 G2 y( `6 I8 ufunction IsaNull(cCheck)         
# g9 G8 }9 v( ]5 d {          % k3 S' D; W4 b) d' ]
return(cCheck != " ")         
3 d; R  X( B% a9 n }                              
$ K( t4 |7 u' j" N0 A2 b8 e! U  D      
( \+ E  _  X4 q' B7 i" |: I1 |function checkform()     
# e5 O6 h+ [' P" W, \{
4 x& C9 x- F. q  id = document.sform1.id.value;     
& a8 t( Z* n9 ?) z$ a8 q5 I3 q# E if (id == "")     
$ O8 \6 h! [# J/ X  {     8 D1 B: |- _( R$ {3 V9 x1 R
  alert("请输入注册名");     
1 N, k+ b& |3 m# I1 `+ N  document.sform1.id.focus();     8 k% C2 W3 l5 y. B; L( S
  return false;     . e) E; z8 E) l, I) ]0 J
  }     . y: [& e# @6 N/ p" S% z! W, d
     + L% u) m9 S# o. Q9 b
for (nIndex=0; nIndex<id.length; nIndex++)     
2 G2 _4 C! Y% w, V/ G7 a4 p+ @  {     0 _: T7 K5 |. T2 H/ `
  cCheck = id.charAt(nIndex);     $ m7 N! N( l/ G; ]% u
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
0 K4 Q4 U. [" n+ Z- q   {     + ?: n2 a, t6 v2 j, @' @
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
. U: t: M! F) g# ~6 ^" V   document.sform1.id.focus();     * U4 q) l1 D& j6 C, m# ?9 \
   return false;     
( G0 z+ `4 s& N2 O* B   }       h$ L. K; N; s: d
  }   P( y; t7 [: D  W/ I
  chineseid = document.sform1.chineseid.value;     
! y- I1 G: w& V0 `8 L if (chineseid == "")     
* z$ Q$ q% F7 y7 r, J  {     
# T5 P3 O; J* V4 w; S  alert("请输入中文昵称");     
0 m& Z, f' N4 y) S  document.sform1.chineseid.focus();     
8 K4 a, {" R' v6 ~; N9 x( w& R$ P  return false;     6 v( h% ]! ~( s1 |
  }    * P# r  P6 T8 v) r/ g8 w7 N
password = document.sform1.password.value;     1 M+ k" a6 J7 p" F/ c8 }$ h
if (password == "")     
/ [2 k. s  f& x  u6 i! a& z- w  {       I1 d, U/ I& f, m" i1 m
  alert("请输入登陆密码");     
0 J# _9 M- W, q# N; V. U- K( G6 S  document.sform1.password.focus();     4 t7 `% Z. m7 s! ^
  return false;     
' n/ G: ?2 U8 U9 A( f& M  }
1 d5 u( ]- b$ s" @, @) I password1 = document.sform1.password1.value;     , ^) K3 E2 H3 R" O! k& d! ^7 i
if (password>password1)     
' N, N% g* Z) B7 |  \  {
2 A6 q5 n- o' u& I     alert("重复密码与登陆密码不相同");     
; e; a, o. E9 g; G2 {1 {8 Y. I+ p  document.sform1.password.focus(); 4 @7 H! n' L9 U+ R4 p- A$ w  \0 f  j
                                document.sform1.password1.focus();     
3 p2 _  O: O8 C7 [; i( k5 i/ X  return false;
( T, S) ]# A) L# j* i  }  
  Q# C( \: D% B" ^' Vif (password<password1)     
* l( ]$ C8 q( S  {) z# f5 O+ C+ D; e# h0 c$ ?" o+ n
     alert("重复密码与登陆密码不相同");     * J' X8 B# K/ ?; W; x
  document.sform1.password.focus(); 1 ?1 S4 ]+ ?# s' y8 }7 a* n& m
                                document.sform1.password1.focus();     
3 F  n& b8 m* U  return false;
* }: E& Z2 v8 @) O8 \: A; L  }
  K: l  c4 t8 c& b7 ]" J% C if (document.sform1.email.value == "")     
% {3 B/ S9 x7 m  Q9 R' q  {     5 Z7 a5 R, I: g* n
  alert("请输入您的E-MAIL地址");     
4 j# Q* Z7 ?/ V$ V5 x9 y/ W  document.sform1.email.focus();     
, k9 Z7 u/ m- G9 v+ `5 o  return false;     
# x) s, M3 G8 b, t" I; C% p  }     
6 ~4 l6 g6 d) ~* }1 \      : h3 v1 r! W2 E0 F& ^' A6 H5 Z
email=document.sform1.email.value;      3 L0 i: z6 C, V! f; W+ c
emailerr=0     5 {2 n# W( A( T2 F' a+ [
for (i=0; i<email.length; i++)     4 x( l6 f* R& J5 F: F. a: |5 r
  {     * d: F- }' J5 v$ x5 r9 @- ]
  if ((email.charAt(i) == "@") & (email.length > 5))     
5 }# m* M2 f& Z   {     - F7 x3 ^, G& b0 x* c  ]+ U
     emailerr=emailerr+1     4 e1 C5 U% L2 S  v+ [1 `6 G( i
   }     
3 R7 B/ A. _( ^  }     8 f; i! G' i7 h, o: l
if (emailerr != 1)     
" o# P3 F" K$ D" a0 w' C! x" h  {     # i0 T  l- s% G) N+ p# E& {0 R! z+ K
  alert("请输入正确的E-MAIL地址");     0 I! b' _: u& W4 y/ l& R' D
  document.sform1.email.focus();     * D. Y  Z5 C$ `( |0 ~
  return false;     - z, h- C: s, G4 i0 G
  }           
# [: G% U9 ^$ p1 y8 k' s  5 ~+ Q! U" ^- ~' j
if (document.sform1.checkask.value=="") * |- C1 B* w" |8 J0 h5 u4 A5 U
  { / c/ A: j8 T, Z  k
   alert("密码提示问题不能为空");     8 U+ Q+ k6 F: C" I- g2 z" e
   document.sform1.checkask.focus();     ; o9 c4 j& z) ^: C
   return false;  , v1 I9 w# Y7 c. }: m: E* X
  }
: B0 T' W, G8 V5 h6 Y) i if (document.sform1.checkans.value=="")
8 b1 y6 Y4 e4 @3 C  W1 f* b, w  {
5 B! l/ F  z: o, ^7 z& Q# c) _   alert("您的密码提示问题答案不能为空");
6 @: y5 [9 z" v% r8 w5 J6 D! c0 f- l7 s   document.sform1.checkans.focus();     ; R) |1 K* j/ J9 S1 V
   return false;  
$ P% k2 P( X' P3 \  }
% r% X: C% V* Q# P+ D  [, `; O return true;     
( E0 b  e% b) I" R) h/ ^     * H/ B" x5 d7 q: l2 V  }' s, P
} ; B+ l2 C: c+ r
</script>

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