返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:: {$ t/ E! f+ c5 N2 y+ y" I1 \
<script language="javascript">     
! L: A- `5 M$ o) d  }function IsDigit(cCheck)     
4 C9 d( k. o# Z9 v {     
6 N' ~: S! [& k/ P+ i return (('0'<=cCheck) && (cCheck<='9'));     
. _( V2 C  @# s( i# _/ R }     - Z+ D5 C1 `  K8 u6 K7 @
     
+ h2 U6 v6 D1 H8 Dfunction IsAlpha(cCheck)     * B" F( r) o9 X. O1 a. M* g
{     ( R, j6 ~$ |9 |; c
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     % D7 g# M' [- S
}              
" f9 L2 l4 T" V0 Q, F4 f      
* y# L! f7 U& B: Rfunction IsaNull(cCheck)          # J% F+ p0 O& P% j8 |
{         
, J; U1 ?' s$ U9 J# [! Y- h0 S3 L% E return(cCheck != " ")         1 w( v1 T! u9 n  n. Y+ {- _
}                               . v1 d1 D% B7 G; m; D
      9 O$ {( N: N3 A, b) y
function checkform()     : D9 s1 e/ G  u8 ?3 I! U# X" M3 U
{   r' p( y: X' e/ R* y
  id = document.sform1.id.value;     
! }( Q/ Z( W7 N5 i* T1 ^  C if (id == "")     
. d: Z6 I1 X0 {' q! ^. X, x  {     5 ]2 C/ k* m: w! v
  alert("请输入注册名");     3 @% l1 A# U6 w) c& a0 d" s/ {
  document.sform1.id.focus();     
' G+ l/ w* k5 w- T! V  i. J  return false;     " A' e* \/ f- o) U3 S3 Z$ a
  }     
4 k0 q2 J' U5 V1 @- ?4 ^     
% S. @; y- t% v for (nIndex=0; nIndex<id.length; nIndex++)     
( c2 Z' w2 z) H/ P  {     
4 D1 b: j/ ?9 S/ y  cCheck = id.charAt(nIndex);     . d; `; Y3 p0 _5 p/ G8 ?2 u+ W
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     % u% G: `1 U9 ]; J
   {     ' N; ]7 j+ o& n) i* x4 v
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
2 @, e; W& B/ ^) N   document.sform1.id.focus();     
7 t2 A0 {, c7 B6 r   return false;     
1 f  f  x) x  j9 X! j   }     ! Q( R8 N+ \; B/ G
  }
6 T9 `0 Z+ z, |! ^  chineseid = document.sform1.chineseid.value;     
2 M  v! c4 N3 {& r+ P0 ~ if (chineseid == "")     
0 _/ o. s( k9 ~. G/ R9 v  {       x5 I* v) H% B9 x8 C
  alert("请输入中文昵称");     
3 r: e2 Y5 }' g; y0 ]  document.sform1.chineseid.focus();     ' E3 l+ V5 W# U8 N  l* Q; o$ Y, o
  return false;     
6 O4 r& A" M4 C' k$ n( |  }    " }! v$ j. y6 m4 H' G
password = document.sform1.password.value;     
6 [3 x+ Z  u" |: r if (password == "")     
, C7 I$ V* Z* x! D0 h0 F5 V' G: B% n  {     
5 S! p  f; b2 _. T( t: k  alert("请输入登陆密码");     4 N+ W7 T- P+ ]% D. z8 Z9 S6 d2 }
  document.sform1.password.focus();     
8 Y- W: E2 b6 A3 j+ J/ n  return false;     9 [9 e2 u/ y+ N) D1 `1 q
  }
; a" p4 ~$ v" U) E" Q0 F6 l4 U password1 = document.sform1.password1.value;     * v3 k! r7 A& [6 V* J- m( R
if (password>password1)     + N  R+ B  O; w5 D; U) @3 ?
  {
/ Q( }: t) a% {+ d- w- @7 X5 c  M) Y# O     alert("重复密码与登陆密码不相同");     
/ P8 m# P- D1 P+ H  document.sform1.password.focus(); 1 U" Z  Q( y; @- Z! u& z. N
                                document.sform1.password1.focus();       s* G; R4 |+ ~' ^: L
  return false;5 i; K* s* ]8 ?5 e
  }  
, E( c" _& w$ F. Y6 d- }if (password<password1)     % ]2 _- x. {( N& I2 ^# B) h5 \) x
  {
! e. }. r) K" U5 w5 h1 k$ ]     alert("重复密码与登陆密码不相同");     
2 M7 z& v6 H- ]# h. T7 I% i0 P  document.sform1.password.focus();
7 E/ [4 Y! Z2 u- }$ C' Z0 Y                                document.sform1.password1.focus();     
$ U/ O* |/ c$ ~: v, a: ]- q( C2 j5 E  return false;3 k- a# B* [3 H' ]. t% i
  }
, z1 k8 k: L2 o  H1 _4 |# u3 n, _& T if (document.sform1.email.value == "")     
0 s7 ]3 d" T1 h/ Q. ?& B6 s8 v  {     
. X. k8 I$ d* U1 l; h0 f: u  alert("请输入您的E-MAIL地址");     % l% M5 v% k8 T4 v5 J
  document.sform1.email.focus();     3 ?1 L: X% ~/ V) L& Y- \
  return false;     
0 V6 ]: z5 u" h; n: P3 G  }     
# Y$ C/ r  k& M' s      
) c+ ~: ]2 X5 B' H/ ~ email=document.sform1.email.value;      
# [  s6 X( b- c# f5 J0 I1 \# ] emailerr=0     
( w2 }- Z# b- P0 O6 ? for (i=0; i<email.length; i++)     
$ o! ^4 F* k8 ~+ G) d( V6 a  ^' v  {     - ]: o& i2 t1 C
  if ((email.charAt(i) == "@") & (email.length > 5))     8 O! Q2 `8 X  S- f, ^
   {     
' A% x/ w- Z/ T( T2 @) ]1 k     emailerr=emailerr+1     / e' @9 x) s0 @3 Z, ^# r3 b, u
   }     
( T+ y, l$ e  w; g! o' i! U1 z  }     1 F1 H8 V  x/ E/ M' [8 c
if (emailerr != 1)     
) U3 Q1 {4 v* L+ h  {     
: q9 G9 R9 t# D+ F  alert("请输入正确的E-MAIL地址");     
  x; ?: e/ J# f0 c0 p% i, m+ s  document.sform1.email.focus();     
6 V" V1 T( ]. m# m$ j  return false;     
" [: M( N/ z$ n( a# K$ A4 K  }           
& I2 [! k2 q$ s/ {4 X  
/ x8 n* y/ E9 ~+ u/ A+ T5 O if (document.sform1.checkask.value=="")
  j& ~* o; W4 a7 n. {+ @2 M5 J  {
0 |/ s" t( G7 U  G$ B3 x1 Z, i   alert("密码提示问题不能为空");     
/ @8 @0 j$ w7 w0 e  S   document.sform1.checkask.focus();     4 v( W+ Y$ Q, c
   return false;  
! Z( E& k5 p- w( P/ L  } - Q* X' [) d$ h) J; J( i
if (document.sform1.checkans.value=="")
- B0 ]# k5 u4 X  { , y& j5 t  Q0 k$ R; m
   alert("您的密码提示问题答案不能为空");
$ b/ `( I$ A) B   document.sform1.checkans.focus();     
0 b$ L, v4 s: {7 s: v; y! k1 h& v   return false;  
, r5 c# Y( C  `2 C) e. Q/ A  }- U+ g/ P# G7 m
return true;     
, u8 U' @4 G( T# ]( M* x     
! w* ~( y7 h6 h+ b9 Z} ( M9 L- {8 Z  g$ Q' H! o. F+ h6 H, Q
</script>

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