返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
2 K+ ^8 G/ v# e& o/ F5 n, K<script language="javascript">     5 {5 g9 @! I6 I/ g
function IsDigit(cCheck)     4 }  I1 A- `3 i; n+ ?6 G/ [4 f
{     
& @2 @* F; Y* \6 a return (('0'<=cCheck) && (cCheck<='9'));     ; o8 t$ w. @$ F$ g* K9 e
}     ) {# R; h4 j  a
     1 Q! z$ p, e4 B4 f, K7 \3 v
function IsAlpha(cCheck)     # k4 Z0 K& I! j9 B& p
{     6 c) Q- m" H: a2 }; t. N7 X
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     9 |3 M) m5 S1 A* {1 w* D
}              / M8 N1 e/ o) ^4 e
      
/ R4 i5 S* O: I: f' Nfunction IsaNull(cCheck)          " t, H6 R" Z4 m5 ~" ]( F
{         
4 Q7 F' Z* ~2 w) @- g# h return(cCheck != " ")         
3 o0 h3 q5 w/ W; n }                              
8 c& z& @9 _6 V$ Z( _0 G      
/ W7 q  o# R. J) K: b6 t9 ~' j. zfunction checkform()     ; ~2 t  `1 `, l. h$ j+ ^
{ 6 {9 O' }# }+ a4 T2 ~
  id = document.sform1.id.value;     
& g! ~/ \2 d1 j' p. c& V if (id == "")     ( V# H/ c2 s; b, `
  {     6 S( R+ \2 e; s
  alert("请输入注册名");     ( d* H* T4 \+ O. F# z
  document.sform1.id.focus();     
' H5 |  x3 z7 I( T) w  return false;     
0 N7 I& \% [1 q  }     
" G. S8 l$ m' T9 m+ |     
2 X5 G0 Z% p' S/ M9 z6 E) i for (nIndex=0; nIndex<id.length; nIndex++)     
# G+ v% e" w9 J! h1 r1 |  {     # o, z+ I2 c$ ~6 X' l+ e- R2 D
  cCheck = id.charAt(nIndex);     0 ~1 _9 D5 \. ^4 J$ x. A
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
, i6 g5 c% M- U$ ]# H   {     
9 w; F* a6 B3 k# p7 ?: E1 i   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     9 r2 I, s5 F! P; ]# e4 K/ Q2 L$ V
   document.sform1.id.focus();     
% @* [( e3 K3 j, _9 e   return false;     
- w5 m' K) }! y# v   }     1 f. |( z* o3 o9 S
  } 3 Y6 b" ^" [, \1 |/ z
  chineseid = document.sform1.chineseid.value;     % K; Y7 F$ }% I% W
if (chineseid == "")     
8 G$ @+ F9 e( ^3 P6 g  {     
7 C5 z9 d& @  S  alert("请输入中文昵称");     + U# A4 k' K8 C8 r9 Y5 D
  document.sform1.chineseid.focus();     
. G) b$ @. ]" @* s6 Q3 n: |  return false;     2 S$ [" T  k; D( ]& T
  }   
# y$ S8 V5 U2 E0 A( v- N4 a/ a/ g password = document.sform1.password.value;     0 K$ G  m" g* O7 X% M* x. w: U
if (password == "")     
& q4 [9 ]& l( n. i, A4 Z3 K0 H  {     
& z3 K) L3 H, s5 s- T  alert("请输入登陆密码");     ( l8 @; ?+ A: [' W
  document.sform1.password.focus();     2 L, g) o( D0 u2 @  M* b
  return false;     & Q8 b+ E: t4 I- b0 t
  }
5 e+ c9 J% e" v, m+ G, |$ j password1 = document.sform1.password1.value;     
$ ]0 `; _$ R" \/ e' E( O+ r6 k" X# ? if (password>password1)     
: t, R  P& w  p4 t  J  {) v  @6 ~8 A! Y$ b3 j! X" m3 M
     alert("重复密码与登陆密码不相同");     1 V0 U2 k, A, E1 V9 c
  document.sform1.password.focus(); & s; R# o% c! N4 N1 {. U
                                document.sform1.password1.focus();     1 o& ~# M% h9 @- W
  return false;) q9 L, P% c& W& \
  }  
2 L/ B& R5 \$ z# q5 ?* Aif (password<password1)     
: l3 f! a0 M! z& |6 D2 C  {/ s0 k% X6 J1 N' D) j% Q
     alert("重复密码与登陆密码不相同");     
1 @7 ~  _- ~& ?  g2 w7 |  document.sform1.password.focus(); 2 W5 Y6 V% S$ Q
                                document.sform1.password1.focus();     3 G$ g9 h1 u/ [8 A* r5 T
  return false;
5 D% l6 z' e! u) w4 r# U  } 8 I. x% L4 }. k+ \
if (document.sform1.email.value == "")     
. C+ [% o& Z, \9 K6 ^5 \  {     
/ H" N& u* V$ T; C0 f# b2 E  alert("请输入您的E-MAIL地址");     2 [/ x* Q! ~; A% @8 g* `/ a. p
  document.sform1.email.focus();     
9 E& F6 p- i, y: R  return false;     6 i6 F' F& y' t2 g
  }     
/ t# {% U* L8 l$ o+ L      $ c8 }  `9 ~& l5 F( t' ?& T
email=document.sform1.email.value;      
$ n% Y2 r& V/ \; F- I8 p emailerr=0     ' `/ F4 P- P- y. m- e
for (i=0; i<email.length; i++)     
7 c: K+ C" E# \. z  {     - i1 f5 j' n6 n
  if ((email.charAt(i) == "@") & (email.length > 5))     8 J3 X1 `# U/ |3 I# N1 R* b
   {     
1 m' a4 r9 c, ?! c     emailerr=emailerr+1     
- M* ]4 {' D! ^   }     & ~7 R7 _5 h2 y( J
  }     
1 u" a) `2 l6 f) ~' G if (emailerr != 1)     8 x4 c5 y! p/ X( L9 p  p6 D: c
  {     2 w4 V# ~4 c* a  p2 Y
  alert("请输入正确的E-MAIL地址");     & r9 W+ i6 O2 n; l' S. ]8 j  J: c
  document.sform1.email.focus();     ; z$ c0 i$ K- ^* _* [
  return false;       d* j+ K1 p* V& h: f
  }           ; B: ?2 f, Z5 g2 v8 e
  
9 C* g- d% r; o: H8 T if (document.sform1.checkask.value=="") 7 u) f" E& _1 ]" E  H, J
  { $ Y+ ^) h$ J8 R' n% ^& d
   alert("密码提示问题不能为空");     
5 K' E" S1 w5 D# b% a- c   document.sform1.checkask.focus();     
1 l7 @  D  W' Q$ k3 q. W% H   return false;  
6 D( b& c5 h$ m4 K( h- ~  }
& a" m) e+ A4 x4 M- b1 Y if (document.sform1.checkans.value=="")
; H/ m9 V$ `# ?5 Q; a& u% f  {
! C& Y. @6 Y  k0 K4 E7 @/ H5 ]7 @& S   alert("您的密码提示问题答案不能为空");
6 o( a  H# w! S/ I   document.sform1.checkans.focus();       e7 F" W0 A7 m' ^
   return false;  + h1 B- G5 h& i; h! {
  }
. h/ C/ i* c) m+ r return true;     : }4 o% r- u: G) b2 g
     0 |. Y' _! C2 U- [
}
5 b2 R4 L$ e: v. h</script>

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