返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
% D: y; w+ h  G; ~<script language="javascript">     ) [2 k. g  d/ H( M: c
function IsDigit(cCheck)     
2 o) T5 ^: D5 ]9 j {     
  u6 z) W0 e; V! p( O- S return (('0'<=cCheck) && (cCheck<='9'));     . V2 z- F! L4 t! A
}     
' s; z) d3 y5 b8 M4 O     
4 E9 Z+ T) B+ S8 O3 {5 R3 z6 W) Afunction IsAlpha(cCheck)     4 |0 F' h2 F& W- |/ |
{     
9 p, l& ^; Y# H- A0 g* x5 t return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
  e! ?0 U' U8 z8 @ }              % U  F0 H* B7 u/ }+ z/ h5 S
      " o+ ^* X* V* {- D2 i# V
function IsaNull(cCheck)         
( X9 U0 E4 u: ~( w) N9 l7 Y {          $ H2 d5 U5 w( u" }9 v2 c8 H5 Y( e
return(cCheck != " ")         & b! g$ K4 P5 e  @( W1 b3 H9 l7 _
}                              
2 V) }( ]' y0 F, M2 ?      5 }' K2 m  k1 E' p* @5 b
function checkform()     / v- d  a- C$ M5 U& `  ^
{ ! I0 y: e1 l+ k0 D! ^# b
  id = document.sform1.id.value;     
) P0 p, f* u8 [9 F* \: L/ F if (id == "")     
. E# y7 \! v& A1 }) e8 s+ g  {     7 _! F# E' |" m
  alert("请输入注册名");     
8 `$ @: k' e) k  document.sform1.id.focus();     
% D7 m1 t% A* v7 I' G4 i  return false;     # g* F% l$ I: h1 C
  }     
3 ]7 ^( B9 z0 F7 v/ b% p# V) B- }- T     / J" v* D' I3 C+ g! [* ?
for (nIndex=0; nIndex<id.length; nIndex++)     0 ]8 j) O, ^) h1 k% p# w5 \: y
  {     8 C6 Q- b1 f8 l# L6 Q
  cCheck = id.charAt(nIndex);     4 R7 v& L; i$ G7 u6 R
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     $ V/ A+ I2 _$ ~& i" V2 k" {
   {     
4 D/ a  ^' f8 |+ I  \8 v( O8 q) r+ U   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
" `: w+ `* ]* C% @7 D$ |   document.sform1.id.focus();     ) z* X* {2 o% W! O
   return false;     
! t- A/ A7 `: m/ W, B" k- X0 l* m   }     8 E+ U5 i9 g- B, d) }
  } / S* t( r. w6 `! F. Z5 p4 M
  chineseid = document.sform1.chineseid.value;     
. g* F. D2 n& U. S9 X if (chineseid == "")     # K0 W0 ^! W- u: Z( A0 Q
  {     ) V( p2 V' c" |; C" |5 A
  alert("请输入中文昵称");     
8 i- P. N7 k, X* h2 C* J8 Z  document.sform1.chineseid.focus();     
2 q' ?  n4 b1 k, b$ ~2 ^9 G  return false;     
5 D- _1 G# k4 _7 E  }   
; h) X" ~) F1 \3 P password = document.sform1.password.value;     
' b8 \1 |( W; s6 o5 U/ R if (password == "")     
% _) z8 }" A6 ?$ y  {     
% [8 d5 n0 H% F% \2 z( [: Y  alert("请输入登陆密码");     * b5 b2 w) L$ {+ W
  document.sform1.password.focus();     * Z& k9 F5 H$ M" o1 Y
  return false;     
# {( z6 s/ T9 ^" J- \% E  } ( e- o+ b, o3 e) E* ?) e# b6 w
password1 = document.sform1.password1.value;     
2 N; N. J' w- M- c! |% R9 j if (password>password1)     2 U# ^# }; h- L0 U" o: E3 f5 {4 ^
  {" O, p, A2 G+ L' H
     alert("重复密码与登陆密码不相同");     
, Q+ q6 v& G4 Y; r- X8 T7 s( F  document.sform1.password.focus();
& I* S* Z  R& x% S& C) K$ U  `                                document.sform1.password1.focus();     8 X- n% H& y5 H0 a: h
  return false;
/ Z4 K% t+ e1 S! \  }  ; J6 P+ H' @% z: x3 @
if (password<password1)     
! G/ G1 `. h& ^7 J( t( X  {
0 r' w5 t" W- N8 v4 U6 p     alert("重复密码与登陆密码不相同");     ! h& i9 S6 S3 ^% o
  document.sform1.password.focus();
' n! }2 ^4 o/ x                                document.sform1.password1.focus();     
4 M$ J1 @. P$ _  l' o9 R  return false;: ]. ?! e1 `# b% O& d
  } 4 Y8 l* o* e5 C' Q" k9 z
if (document.sform1.email.value == "")     9 j4 f4 H6 }! r& i4 G
  {     ) b/ W# {' S9 b, d5 v$ f
  alert("请输入您的E-MAIL地址");     
3 T4 U0 v' H& n( B2 l! D: P" V0 x! w  document.sform1.email.focus();     
; @/ k1 Y0 {7 F: Q  v7 o0 z) Q  return false;     
5 w# k% p! M) s% i. a4 s+ M; q  }     
2 a1 R- H5 g+ @1 `+ w& U' E: N      
" u* R# b$ u) `4 B) p email=document.sform1.email.value;      ; `0 U  Q7 ?" Z0 ?" n% I
emailerr=0     
& }' |7 \8 I3 p% E3 K: X for (i=0; i<email.length; i++)     
% R' r, }1 s/ h. X- `  {     
  H6 E" c" W9 P# h/ t( K+ I  if ((email.charAt(i) == "@") & (email.length > 5))     
( k& O. m, H4 F   {     ; v6 a" B1 q- \" t+ z
     emailerr=emailerr+1     : U# j7 m+ `6 V; k
   }     
' F0 X( R/ f3 Z) a  }     
% d, ^+ e! k; E0 t if (emailerr != 1)     
: E3 E( z1 A' f# i- Z9 O  {     ' _& X6 t9 g7 d8 o, u+ d, ?) s9 I, {
  alert("请输入正确的E-MAIL地址");     1 M1 ~& g7 D, e0 h6 [' S: V) ]
  document.sform1.email.focus();     2 Z; `8 ]) B' K
  return false;     7 k! n6 \- P% W
  }             T9 k! s4 w" E# {7 L' \. M# t
  8 P, D" n2 B  ?% F8 [: }, d' k3 y
if (document.sform1.checkask.value=="")
0 `( H9 W2 l: e# q) K6 ~0 A  { 7 o$ B3 D6 F6 z  W! w0 A
   alert("密码提示问题不能为空");     
) C9 U5 `4 [  g. B. s   document.sform1.checkask.focus();     ) H; ]% H5 y6 d+ z, K* c' g! z
   return false;  
: D  s0 a0 p  @! k& I  } 5 `5 B' q& o" g
if (document.sform1.checkans.value=="")
( i6 [& Y7 _" O. E$ U1 E  { - V( s* M/ c- A9 V- ]
   alert("您的密码提示问题答案不能为空");   r( q9 O2 E& i" x
   document.sform1.checkans.focus();     ; W/ }4 v! u, r
   return false;  ) h  U4 w+ v$ p7 P) v3 t) D7 E
  }% U! f  {5 h: K' o+ v: M( S
return true;     + ~9 s% L. C8 k- T* R  s
     # k; P9 X2 ]6 c
} - [. _. |6 `7 w' o
</script>

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