获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:. ~1 J+ u0 o1 l1 W
<script language="javascript">     
/ s2 N6 E& J7 R3 O% d/ B+ yfunction IsDigit(cCheck)     . W/ Y) W( q; R6 I: `* F  P! \8 P9 J
{     
# E) e# o5 }7 ], x return (('0'<=cCheck) && (cCheck<='9'));     
" {% m+ g! D# Q% f% k, `- t( e0 v }     
6 r& H; R1 v( b7 @% j7 Y     
6 _1 ^' N) x5 x' y2 T/ g; Kfunction IsAlpha(cCheck)     
3 i- C4 c( m7 h9 D7 o% w {     
8 {- n2 h" h  q0 y1 K# x4 O( ? return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     / d! s, q/ w  ]0 d1 e( T: I
}              2 S) V; B8 R$ q) d* {
      
7 `8 G" i2 q8 {$ ^9 s' O, Vfunction IsaNull(cCheck)            C* m/ k, a# R+ s( \
{          ! _6 i$ x$ i0 i- n$ ~* s
return(cCheck != " ")         
; F" }8 }( I3 D" g }                               5 T+ `3 e$ W7 c) m
      , S$ t, c. `- q6 k2 D
function checkform()     1 t( P) S" m0 ]+ ^  ]1 N
{ - M4 q7 }! ?; `3 u
  id = document.sform1.id.value;     
# h: W" u2 b4 z if (id == "")     - e& a7 _: P5 t. \* f) Q- x" l$ L
  {     6 Y% d& U7 S: z" s8 G1 t% d7 f
  alert("请输入注册名");     
5 Z! W" ?2 g+ ^- r* q  document.sform1.id.focus();     
: Z5 y( ]6 P) m% x$ \- c/ o# W  return false;     
' ~2 T7 Y+ J* y% V3 P1 N/ v  }     
; S8 v3 q9 E; [$ _     3 u; X$ h9 u$ I1 D7 F. l8 T  _
for (nIndex=0; nIndex<id.length; nIndex++)     : v5 a0 [! V7 p0 I. w$ J" I
  {     
" v: Y- e$ ^% O2 F  cCheck = id.charAt(nIndex);     
2 l0 V" r% s  }1 C  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     1 u' t! Z" d3 h! Z5 T# M7 i
   {     4 a( F: e8 b( [( Z
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
, \" s4 T4 i0 [+ u. M7 v7 x1 e6 @$ I   document.sform1.id.focus();     % a' ]; [% w' D& X8 V
   return false;     
1 q. W: }2 d6 C: j! m: _( Q  }4 t   }     
( m3 ^+ d0 |! d8 p: P  X! W  }
7 y& j9 j5 O. l( Q8 q. Y% ?  chineseid = document.sform1.chineseid.value;     
+ j5 j% p  J" b" b, _ if (chineseid == "")     
- u+ n+ T& }4 t1 u; Q- u  g  {     4 q' M( t3 W6 ?+ [: B( {" K% n
  alert("请输入中文昵称");     5 p0 U, J1 y9 T( C5 S1 a3 k' U" k+ O
  document.sform1.chineseid.focus();     
: b! i* Q5 M8 {+ E0 N, Z) Z  return false;     
% Q4 ~$ |8 A$ M! \  }    ; e( n) }" A( I6 q# F. C% X
password = document.sform1.password.value;     
3 ]6 Z& q& V1 A1 C+ l: H if (password == "")     3 i( e. z1 s, p6 I
  {     
( Y' h( k5 H5 o4 V7 T( z& f  alert("请输入登陆密码");     
5 m( e# w, a" p$ n4 b# ]6 W5 g  document.sform1.password.focus();     
( p% A5 w, c1 W# D& p  return false;     
  d$ W& n, c, a  V4 o; j9 w7 I( X  } 7 d/ |/ s' E5 ~  f
password1 = document.sform1.password1.value;     
! ~' H3 }( D1 a' w3 e3 F+ b if (password>password1)     8 v6 z( `5 }' }' \! f0 {5 ]2 N
  {( W. _+ W7 e" d+ M- G' |
     alert("重复密码与登陆密码不相同");       k9 k* R5 [3 m4 l; M
  document.sform1.password.focus();
0 D/ f' y1 I8 ^9 M- ]. b* }3 G1 R                                document.sform1.password1.focus();     0 O) N1 ]& c& t- K. l' C$ E
  return false;0 L& S% f0 l5 X
  }  ) m' G5 P( F7 |1 a% E  F
if (password<password1)     
) U$ v4 ?2 |5 n  {
0 z/ h' T- u' R- `: F0 G  a     alert("重复密码与登陆密码不相同");     6 j- S, j# S  v' ?2 y
  document.sform1.password.focus();
6 F2 Y- ?* G" C                                document.sform1.password1.focus();     
( @& y8 v* z- U% k  return false;: m5 j% t/ R4 r3 W
  } 0 M$ Y7 e/ e4 \, x% v) }* ?
if (document.sform1.email.value == "")     " ?1 a0 r1 j( T, E
  {     
5 ^( u: u5 B% Z. b. B- O  alert("请输入您的E-MAIL地址");     2 V5 `& R) J# ^
  document.sform1.email.focus();     ( l! ]2 i( N  W1 k+ Z% Z) e
  return false;     
& U: Y0 V0 I' I) [  X9 g& P  }     
" R! m! \( t1 w: o, i1 _      1 ?) o, d% a) [; L
email=document.sform1.email.value;      
1 N5 d. y6 V' k4 k6 Q emailerr=0     
* M: M0 R. u! L) y for (i=0; i<email.length; i++)     & W0 f( X9 ~1 @
  {     
* I0 F; M: V4 `! Y2 p9 @  if ((email.charAt(i) == "@") & (email.length > 5))     ) R3 n) o9 o$ @3 a8 t% A
   {     
( ?+ K. F8 n, k! j6 L- n     emailerr=emailerr+1     
# M/ p8 H1 C% y0 G   }     5 C2 `3 a/ ~4 w5 R1 Q
  }     * p, C3 }1 _* x
if (emailerr != 1)     
: _* \2 w9 m0 m' v& ^0 @  {     5 A5 d, p, W1 q, D/ ?
  alert("请输入正确的E-MAIL地址");     8 ]  C9 V' G7 T( ~. T- ]# x4 F+ `# x
  document.sform1.email.focus();     
# A7 t0 w% j7 a  return false;     
0 Z$ C, U, p: q7 _  }           
6 h0 q+ d: J5 I. A+ _  # y" ]; b5 z! f% s6 x
if (document.sform1.checkask.value=="")
, D0 W* B' e5 N% U  { ! F6 X: d  \" K% o" d
   alert("密码提示问题不能为空");     
; H" u$ n; D0 m8 L# |$ C   document.sform1.checkask.focus();     
3 b/ I) [( T) ^2 m& s( F* U   return false;  
6 v7 p2 b4 {# \  }
/ W% J  T3 `6 a4 x2 n. ^* _ if (document.sform1.checkans.value=="")
9 e; |4 ?8 W  v7 x) ]$ k  { 7 o3 a% k1 J9 y5 d% E
   alert("您的密码提示问题答案不能为空"); 3 V# G  h) u6 [  I/ r7 y% _3 v
   document.sform1.checkans.focus();     * q: E% }$ f$ \$ P- v
   return false;  ! L8 F/ i/ {' r" i& w
  }
. ~' U" b) o5 M8 h- K return true;     1 h4 F7 R" G* h: L0 B% c# m8 Q0 `
     
% ~& Q- {7 H$ `. E* K, k) C} ! ^4 {* z$ r7 i$ J) Z8 S. Z
</script>

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