返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:, M/ L  p' p$ T6 `& H, w( L
<script language="javascript">     
& \% E! z  S/ X+ mfunction IsDigit(cCheck)     
0 c. L1 M" }* p1 i {     ; t, v) r" _0 }3 n4 d
return (('0'<=cCheck) && (cCheck<='9'));     9 s" U" g) K& R& l# T
}     - ^. s8 R- f. V1 @& \' N7 X4 y
     
: q# }3 f$ r+ q8 C+ Cfunction IsAlpha(cCheck)     
' x2 y( a- u  D7 g8 \( u; H {     
$ j' Z: S7 J2 Q0 X return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
' b) P" X5 m/ y2 b" } }              
+ V! U; q% \' X% m: Q      
0 d- f2 D5 Y6 q, {0 z- Ufunction IsaNull(cCheck)         
, s& X9 [' f1 C- {, B5 X {         
6 C9 \5 x) f( L9 D return(cCheck != " ")         1 r" B& w, U- _$ a
}                               ' f9 D9 V1 Q( s. W; ^. d9 i
      / K# o+ q) ^9 [8 q+ m" X* S
function checkform()     
+ l: y2 b& U- n3 ~8 @. u2 q{ ; f, g/ N7 U( k9 P& K# h3 J
  id = document.sform1.id.value;     
7 y8 I6 P+ [, T: X( N5 X% y if (id == "")     
8 F, H( u: A( |2 d  {     
; U- b- `7 k7 b, a" d- j; {$ B5 T- e  alert("请输入注册名");     : }, L0 m$ K! q$ u& c% M
  document.sform1.id.focus();     
; `5 W8 D' A  Z/ J  return false;     
. {! h. P: [6 g& z& A$ e  }     2 F; X2 B  Y9 I
     
: D+ n" y( u) s' k% {( b& a/ n3 W for (nIndex=0; nIndex<id.length; nIndex++)     
' x% L' s+ w! T1 }" J6 h9 z9 ^) c, x+ W  {     3 w! K) w  {& [1 W6 L- W+ s4 F4 Q( c
  cCheck = id.charAt(nIndex);     
5 e! D$ Q4 K( O3 V  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     " t' [) s: M4 z  h% j' \
   {     
7 h6 ]0 a: `, i3 V$ l' s& D9 \   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     . E2 @: Y2 H5 a% G5 Q1 z
   document.sform1.id.focus();     5 m" j" h) l$ M1 |
   return false;     
& z6 j3 M2 Q: @5 ^& ^$ Z   }     0 n1 u0 \7 W7 j: [3 Z! E
  } - m. C4 }* u& x
  chineseid = document.sform1.chineseid.value;     6 v. \- f# y8 l' m' D
if (chineseid == "")     8 p6 a$ u3 j+ W8 @; M7 K
  {     3 h9 j0 C! P% w: f, P! Q  X" N/ {
  alert("请输入中文昵称");     2 s9 {9 p+ Q4 M# K% X' h' d6 v
  document.sform1.chineseid.focus();     
! ?% b) H" C& Y  return false;     
. G$ c9 f( K6 G  }   
; g+ N% {, y" r! _ password = document.sform1.password.value;     $ R. M! r9 v& t' ~
if (password == "")     
) {' }- M# w* I5 S! c  {     1 `5 j& m# r) W
  alert("请输入登陆密码");     , L# A2 h  Z# Y) _& ~" L4 Q
  document.sform1.password.focus();     7 e" L6 s" T: ?5 E# m! x# o6 j
  return false;     $ y% N1 V7 z& b8 x& C, C
  }
" o( ~: B9 O3 M) l1 q* j; {# J. ] password1 = document.sform1.password1.value;     " V, I! U0 n) Z  t  ^9 Z* ^
if (password>password1)     ! L) D8 R+ E2 Q1 S5 m, k. ]
  {  n1 f2 W8 T1 Y5 G  j% J2 e6 A
     alert("重复密码与登陆密码不相同");     * k0 v4 a9 }: A( A: q
  document.sform1.password.focus(); " I( Z' x7 F& {0 S$ m. ~/ i  H
                                document.sform1.password1.focus();     , u, ~  ]  L6 J5 ^7 n4 @
  return false;' R" I% z+ a$ E2 _" C8 A% D, \
  }  
* i9 F0 h6 l/ H% xif (password<password1)     
( @. l) K2 n9 ?) [  {
" W3 `  F' v$ b9 E, F     alert("重复密码与登陆密码不相同");     3 H6 m0 |. a/ m6 F* d
  document.sform1.password.focus();
7 P+ |7 \9 ?8 Z- j3 }                                document.sform1.password1.focus();     
3 V' p0 l6 z4 {$ }9 H  return false;9 K/ z# i5 U) U) J5 i/ X7 C4 M
  } 0 K" f2 z7 N; x+ L
if (document.sform1.email.value == "")     
2 H1 a$ L( W" A8 Z8 D6 M  {     3 H2 H. l  F  ~% |% o
  alert("请输入您的E-MAIL地址");     ! F1 K& T7 t# _
  document.sform1.email.focus();     . M- C* f; D8 _2 i" ?
  return false;     
  g, z+ B+ ^& }  }     
6 a1 R9 l! X2 v+ G( h) b      3 c8 j( z  i/ O- C: U5 x
email=document.sform1.email.value;      
& N$ ^" W8 \7 U( d6 y( w emailerr=0     9 Y! R. V7 e7 d" S" s& ~+ S6 P% b
for (i=0; i<email.length; i++)     
& f  q( i- J/ W# B4 [9 M  {     3 z) V( d7 ~0 p1 ?1 b
  if ((email.charAt(i) == "@") & (email.length > 5))     
  D9 j4 K, Q/ a2 {. m* u   {     
% ^7 Z& N) k7 h$ k! ?     emailerr=emailerr+1     " d' C5 s: J! D5 _( ^- p- ?
   }     
7 q/ l9 ]. \5 M- T# q5 E4 Z  }     
$ o- B4 M- \8 ^' w if (emailerr != 1)     ) R+ M2 _  X; I* I& C, W
  {       X: |% `0 u( q" r  t
  alert("请输入正确的E-MAIL地址");     4 k4 A1 p' Q$ r- N$ y9 H5 f( }
  document.sform1.email.focus();     / r6 g9 J: ^0 f" h! f" W
  return false;     4 U7 ?" O/ S$ m- O# ^8 B. @( F4 ~8 m
  }           . U5 i( m+ K6 s( E$ T& q
  
1 F, B( C$ T) ?9 h6 z' X if (document.sform1.checkask.value=="") - Z7 M& y7 o6 k& ?9 C0 K1 a
  { 4 v! U4 y' \4 U' m% _( K0 [5 k. `
   alert("密码提示问题不能为空");     
4 p/ M+ ^  f/ t   document.sform1.checkask.focus();     ) `0 d, ^* s& w5 i2 G
   return false;  - W5 o1 L) @9 O! n, E) B; f0 `
  } 3 \  f. V; r/ P7 u3 v0 f
if (document.sform1.checkans.value=="")
* l- ~1 R5 l+ S' p* l& G  { & ^$ @/ h8 {4 X. W
   alert("您的密码提示问题答案不能为空"); , b( V( p; l, {3 t3 F/ R  t
   document.sform1.checkans.focus();     
9 S0 N4 s2 @: D9 Z   return false;  ; m" B0 X- K0 Y8 Y$ g) q% P
  }' o. [" c  J2 L; c  a
return true;     
* C8 k* ?& {% ?9 E     
1 a( _# m' J% j- \( Q4 l, F} 1 C$ s. m+ d( T) m% W" Y$ R
</script>

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