返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
) n5 m* y* n/ f* i1 l/ T<script language="javascript">     
9 ?2 ~( V! r7 G" j2 P( zfunction IsDigit(cCheck)     2 w( M) l" t0 E+ x5 Y5 G0 P9 ^
{     ; i+ j" B2 k3 f! Y6 v2 g6 H* ?
return (('0'<=cCheck) && (cCheck<='9'));     
3 @& h' O/ I( f. K* ?" t3 I; `& U }     $ ~8 U: h+ ~3 U( S4 @( ?9 K
     + q8 l; L# A7 D3 ?& S, I- _5 w) \
function IsAlpha(cCheck)     
' Z3 y3 W5 {( V7 t {     ; ]* ?; u( M4 n* x8 U( S9 l
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
- D6 V0 m4 t/ G+ O }              ! Q- B3 ^6 A# m% o! r
      
) a1 ~, a0 Q; O6 E4 ufunction IsaNull(cCheck)          4 ~; v/ Y, l2 J  _% B  [
{         
! g, y+ i6 O* f4 |, @ return(cCheck != " ")         
, i/ {: W( k8 s3 ^6 A# Z }                               " t; U" X9 E. k4 H- E
      2 H! J* @. f7 S2 T* f6 D+ J, ]& ~
function checkform()     ) U% `2 L% g, T2 \6 O3 W3 z, z1 g
{
5 R/ }) y- H9 `6 j  id = document.sform1.id.value;     
& c' j8 R3 Y' X/ y if (id == "")     
7 U/ e# C6 \. V% ]  m  {     " Y$ J9 E& X' z  a4 \8 `
  alert("请输入注册名");     ' T* R; ~! R% @' `; s& H
  document.sform1.id.focus();     0 B% C+ T5 y. k4 T: y+ t, _' E
  return false;     / p/ T8 H# t& d  `5 m2 R! h- Q
  }     
5 t9 e5 ~; h9 a$ L% V  m     
3 {- Z& V! g: u& j8 ^ for (nIndex=0; nIndex<id.length; nIndex++)     
( _: D' b+ r4 Z: h  {     
( b* ]$ P# {* o( T  cCheck = id.charAt(nIndex);     % s: f8 f/ o. {5 C; K6 m$ X
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     4 g4 _+ E* i. m2 s' J
   {     * _& a+ V) w* Q1 L- t1 x
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
0 C6 q* |: z; ^& v" W   document.sform1.id.focus();     & L* m6 J* i- ^! X$ ]9 Q
   return false;     
' O9 m5 Q. t: r; G/ g0 r   }     % p% {$ A+ l  W+ n( p2 ?+ g6 V; b+ F# y
  } 7 [2 z( q' m2 B* w: M6 q7 c
  chineseid = document.sform1.chineseid.value;     
6 s# m  a) ~3 I3 V if (chineseid == "")     
8 G7 l& X9 L8 w9 u# ~  {     & [2 g7 s( V" }0 ]. C# N8 U
  alert("请输入中文昵称");     0 n  N# q: C% M2 X/ P# l' N( i( M3 l
  document.sform1.chineseid.focus();     9 X$ I6 D$ B+ H4 ^
  return false;     9 N2 s* L0 q+ y3 h" D
  }    ; L, U4 v; B3 u. R# u
password = document.sform1.password.value;     7 l+ O  V4 \; a; w6 {1 j
if (password == "")     
% @9 r5 C9 k& g  Y  {     
% R" |! H: X8 I: g  alert("请输入登陆密码");     
" o5 j3 t0 K  C& l( M& @2 h% }9 C( L" d  document.sform1.password.focus();     ' r3 H! a! x) x0 ]1 D
  return false;     
5 z- I; F! ]6 o/ h+ s1 l  D  } 5 W/ o# V4 O: {' U  T
password1 = document.sform1.password1.value;     8 b( C' O" U5 }6 L" \
if (password>password1)     " y  k0 T0 p0 s
  {
1 y3 C/ R( ]4 Z5 o6 P  m( \     alert("重复密码与登陆密码不相同");     
1 J1 X8 v! t5 K0 ~. G; N7 [+ b  document.sform1.password.focus();
! S+ [6 n9 E  s0 c$ ~7 P                                document.sform1.password1.focus();     
5 N3 G0 A* K/ h  c9 R  return false;
* z) R- v# o1 f" X9 q5 p  V6 u  }  
8 a( ^: q" ?: ]8 J3 T& i, X! g3 Z2 k" Vif (password<password1)     * |# C0 T2 B* s' \
  {
0 N! b( b' d. [+ ]     alert("重复密码与登陆密码不相同");     
" q. t& R# c6 ~# T; _2 }  document.sform1.password.focus();   q! G2 x! b# [
                                document.sform1.password1.focus();     ! ]  p" ]/ D8 Q& T8 [
  return false;
0 |4 X( b% }8 \' W( ^3 U, o' Y  }
3 r( }+ J5 p2 F/ {  M; f7 C if (document.sform1.email.value == "")     ! S' X+ E% _# M4 l9 x+ _
  {     7 s! a" `4 T) B! ^
  alert("请输入您的E-MAIL地址");     ( N$ ^  J' z$ W1 ]8 `0 s6 K2 x
  document.sform1.email.focus();     / m6 `9 S' l0 L8 w7 \
  return false;     
' y: X) L$ |8 d8 h, D  }     
' u6 v/ B9 F# u/ [  T0 V% d      1 s9 n; v0 H9 @0 ~
email=document.sform1.email.value;      
2 e) T7 b& G* p) { emailerr=0     ( \6 ]8 E, W" \  u& x* F: j
for (i=0; i<email.length; i++)     
* V( l6 r( m0 z$ q/ K$ l  {     5 m1 r$ ^! y4 Y5 @" O2 a
  if ((email.charAt(i) == "@") & (email.length > 5))     ; s: Q& U+ U: O( \0 y( Z5 c
   {     $ g3 W: G3 I0 k6 z- i6 P6 l$ o# i
     emailerr=emailerr+1     1 K0 M6 v& c2 x1 j+ W, \
   }     9 O. l3 d1 o& f
  }     % h( X5 }' h! R5 C
if (emailerr != 1)     
$ ]& z  e; A# r2 X& c  {     ( c9 `& w6 W& f+ J6 h8 I
  alert("请输入正确的E-MAIL地址");     4 N& s! T7 Y4 x8 x& k2 B
  document.sform1.email.focus();     
8 u0 n2 T( h+ q5 @6 o2 U  return false;     , b) m; p' C& d; L* @+ d
  }           ) z7 f; B1 e4 J$ X
    O$ p$ L: Y6 M0 ~; X% q5 s
if (document.sform1.checkask.value=="")
9 R, K) e( K  q; `5 C: Z. {  {
8 \. _+ Z* }; @: @' w   alert("密码提示问题不能为空");     " ~! ]' g: d' s
   document.sform1.checkask.focus();     
& V* b  U( f' d   return false;  % t* K( ?9 y5 T, `* c% q
  }
0 V5 K$ K, ~! P" j# R! L* t if (document.sform1.checkans.value=="")
3 }& J0 o5 y* h- r; G, G; Z  { . ~8 ^6 P- Q, a9 [  b/ v
   alert("您的密码提示问题答案不能为空"); - {) }' N8 d. o* z2 M( l1 ^
   document.sform1.checkans.focus();     
( A4 b. e. S6 o* {8 J7 G   return false;  0 n- o4 T6 X% H4 p7 E
  }) h, v+ o8 @0 _% u9 ]# G) p& O
return true;       A/ t' S# \: E% h# Z
     
/ l3 o4 B. |2 O3 w} + q; W: f2 b8 U3 n( |  d
</script>

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