返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:/ q! \. K9 C6 S0 c2 O: W
<script language="javascript">     
* n$ q2 Y3 i! B  B6 ffunction IsDigit(cCheck)     
6 Z! y9 p5 K% a% b% T& P {     
  T7 \3 J9 D. @  t* i$ e# e0 S return (('0'<=cCheck) && (cCheck<='9'));     
, x  }; D/ j+ c: c4 G }     9 p, ~$ `0 q' X
     
) ~$ m. o! c7 ~8 X8 C  Dfunction IsAlpha(cCheck)     " |+ {. `  t( Y
{     - U4 F, h; G9 J% J% |. w5 W
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     % V, Z5 H1 w- @2 U1 X
}                k5 \) k# k' H
      
) w$ h" c: H9 w/ s. K3 e# [function IsaNull(cCheck)         
: B+ B- v% y5 ~ {         
$ R# a/ t6 N9 U7 z  W2 u return(cCheck != " ")         % v3 e( l  I: L
}                               , ?% X7 K; w, Q+ d# ?
      
: c+ a0 i$ t) i. Ffunction checkform()     9 I' I9 a2 d, b* E
{ * J3 M8 r2 q5 d% r( ?3 _% Y4 ~
  id = document.sform1.id.value;     
3 f5 e4 g4 @! w6 T) F/ d  o if (id == "")     ; i4 h) v, R3 d; R0 T
  {     
3 @: a& S+ `7 l  alert("请输入注册名");     5 Z! n# g- b8 T3 x# _" a- g* P
  document.sform1.id.focus();     ( A; d7 R% j* W8 n: I! @, Y
  return false;     
2 n* l6 G. T: i4 g4 f( U- q  }     
# a- g, G7 l2 B1 j% E     * Z* F2 O9 O, U! m( d
for (nIndex=0; nIndex<id.length; nIndex++)     ! k! _+ i5 D( D
  {     # {1 T" j5 e  d! F  V  `0 v5 A  G
  cCheck = id.charAt(nIndex);     
/ b/ K# ?" S' Y) j$ d; x  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     6 ~" o: i; W) D0 j" O) U, t
   {     # ?  `. a1 e8 j0 R/ ^9 B) r$ X
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");       ~7 A9 P9 J( f8 x( N( k$ [' W
   document.sform1.id.focus();     
; T# I) X/ O$ Y9 z4 m3 H8 A   return false;     0 ]7 q/ ^) k! }9 L4 Y$ S
   }     ' J3 e: Q. [9 y$ I, [4 P. ]+ m8 x
  }
: V: J( k+ c# @$ m' I% s  chineseid = document.sform1.chineseid.value;     ! P$ X& T* E1 y" ]( m: t3 p6 F
if (chineseid == "")     # d4 u/ p, `' r" C4 b/ q
  {     : k/ ^1 p( S% B8 I( [4 ~# B
  alert("请输入中文昵称");     ' J2 s: h3 y# D; z
  document.sform1.chineseid.focus();     
1 i2 N5 S3 U9 p# i3 l/ x/ X; _  return false;     5 W( Z# Q$ I$ a4 ?, E8 s9 M* t2 \
  }   
* @/ U! [! x3 v password = document.sform1.password.value;     " w  y6 q, Z/ x; }+ ]0 b
if (password == "")     
& [- `' L; F- b1 w" Y  {     $ b: E" x) i  g( b9 h: |
  alert("请输入登陆密码");     
  H; m4 R* ~- f4 k, K  document.sform1.password.focus();     % T0 L8 _+ ~2 `$ K7 w4 Z4 Y
  return false;     - {! _" y5 g0 u$ P& n
  } 5 H7 F3 P" H4 p$ @) e% N
password1 = document.sform1.password1.value;     
1 P& g1 ^6 U0 |+ N" M if (password>password1)     
0 H) I& g. [& @* f) I! l  {
, E; M5 V  Q: |1 [$ I3 {8 }6 R, I0 X( F     alert("重复密码与登陆密码不相同");     
# U: ]6 `/ J& y1 }' O4 I  document.sform1.password.focus();
, f( }. p- D, n5 h/ J5 x, t6 g                                document.sform1.password1.focus();     7 }8 X& ?" D! z! i
  return false;
" U. v- [: T: b* ]8 j2 K  }  
' ~4 ]( G7 [0 s9 {  T5 q; s1 o" sif (password<password1)     
! W5 k2 X4 v9 q( G, N" \  {
& u4 M5 w& ^: g, Z     alert("重复密码与登陆密码不相同");     
) m0 P- w- t5 o$ h  document.sform1.password.focus(); % D) X# B4 D: O( \( }' }$ e6 P1 N
                                document.sform1.password1.focus();     
6 `4 y& n1 ]5 o  return false;
- @4 I3 c, t" O) j* @4 f  } 8 S0 v# ]0 M- H  c! }) p
if (document.sform1.email.value == "")     1 A( A# g* ]. _' \
  {     * t: s% ]- r. [  s1 }5 n
  alert("请输入您的E-MAIL地址");     2 z6 l& F- O1 K$ D
  document.sform1.email.focus();     
) V) n9 O+ Y- U9 Q& z- Z  return false;     ; K: b$ N5 E; a; ?+ y  f
  }       V. `/ A) J! r3 l/ t
      
# {0 i3 q' y& P. I4 |- w9 N email=document.sform1.email.value;      2 U1 K/ i9 M, u. o5 y/ }$ |
emailerr=0     
+ {  O1 {% }! I' A for (i=0; i<email.length; i++)     
5 _# ^/ D" W1 o" R( s  {     
7 ~' }1 T+ S& r! K1 k  if ((email.charAt(i) == "@") & (email.length > 5))     / I$ g9 o5 _' B+ a2 g
   {     
$ S% x5 e! z* s8 }     emailerr=emailerr+1     5 ^! F- g0 j0 o# }
   }     
% B$ D! u6 c* W5 n$ A4 r5 B  }     
" @- B5 Y' g5 r1 Y- i6 X if (emailerr != 1)     
) A5 \( a! c  b$ v4 v" c  {     7 \8 k. @' e% w( g
  alert("请输入正确的E-MAIL地址");     ! \. w  j8 x2 g
  document.sform1.email.focus();     + p4 g/ {8 ?# V* z. G3 t7 s. N
  return false;     * I; h* G8 K3 @0 j
  }           
" L; j9 T) ^. W/ u  * {/ R/ U0 X+ l% h6 }
if (document.sform1.checkask.value=="")
" I+ Y4 d1 P$ a2 B0 R* `8 P( r9 s  { 2 }( w" H! [7 Z4 U
   alert("密码提示问题不能为空");     
9 z4 x# M/ k7 s# U   document.sform1.checkask.focus();     
0 L, u( ]- q9 O$ X   return false;  
; ?% H3 X  L( L  } 4 [7 c" l  \( x5 b/ Y
if (document.sform1.checkans.value=="") * F9 C! d9 l4 V; ~
  {
: |* I% y& S0 g4 S! e! @. \   alert("您的密码提示问题答案不能为空"); ; N' s: x$ {* p. p& J: W- s7 ^8 M
   document.sform1.checkans.focus();     ' a" c+ b* r3 N, \, B3 X8 K
   return false;  
+ c" i. V& ?9 T2 E- w  }. r& q; o, c* @" {2 Q/ x
return true;     & c# k$ U; u2 I" |; [" {( z* l
     % ~- x% R3 m9 z% f5 H# F
} 5 M( @* C6 i3 I( c  Q- ?% U
</script>

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