返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:9 k, g8 }, q; h9 @% C
<script language="javascript">     
8 w1 Q. W! I) P# L$ ]) a% Ffunction IsDigit(cCheck)     & \: o# }( U/ B/ W1 F
{     * I/ @  t* g0 S% _& J
return (('0'<=cCheck) && (cCheck<='9'));     
7 Y* `, g3 {3 i$ c3 \. P$ F2 A }     8 b8 [  {1 `# ^3 ~- J
     
* k5 B4 {. G% N$ n( O5 J6 zfunction IsAlpha(cCheck)     1 ^  }* t+ J$ F$ t8 Y4 Z  I/ h2 p
{     
9 c8 ~4 o4 G, P& M5 B* | return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     7 N# r& X  {4 G/ C0 }4 ~* Y4 j5 g
}              / w& W" ^! }( ?9 w: W$ ~
      - D- Y" V/ P. B3 Y0 Y  D# g
function IsaNull(cCheck)          6 B9 V. \! |7 n8 W
{          + |0 D8 ~3 K2 ?8 _  B" y4 r
return(cCheck != " ")         
, d4 ]' v8 \# `1 o. a }                               . ]  K. V0 E3 q$ K4 v( Y! I
      
; I6 \( q% c4 Dfunction checkform()     
' d% k; `1 e9 R{ + i5 A) T  M/ w+ k0 p& {
  id = document.sform1.id.value;     
7 i3 ^4 d# p9 r- |" p if (id == "")     
4 s6 S' E8 Y9 R/ @8 D0 i" e: h  {     
7 {. d# i- Q) g% w  alert("请输入注册名");     
  N' t; e4 q: g6 o" N7 j; G  document.sform1.id.focus();     
& J1 f- Y6 m( Q" v- k- w0 d  return false;     
* w+ c7 L3 K3 Z2 A$ q4 T8 p  }     
% ]" h- F/ q' ^: l     ! L5 U) l8 l3 j, R
for (nIndex=0; nIndex<id.length; nIndex++)     
$ A3 _& M' u0 U- i$ S  {     2 N6 W! D3 v; ^2 j
  cCheck = id.charAt(nIndex);     
  b$ _3 p1 |- {. t  m  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
) n# m# V9 w7 e2 g8 L   {     $ g: |# t: U3 V
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
. @9 Z% v1 k, A- M& L   document.sform1.id.focus();     
2 S  z8 \# q8 R9 t: {/ y   return false;     
- ?  ]8 n* D3 P7 Z, Q6 Y( A   }     8 Q/ \+ M  B4 F* h4 a/ R; O
  } . ?$ d1 c0 U: l% A
  chineseid = document.sform1.chineseid.value;     
; i% V' G- d2 M$ Z4 `  R# O if (chineseid == "")     
. ^) ]2 ]% z4 s" G- t" W* v0 X( `  {     
& c* ]2 J! h. s  alert("请输入中文昵称");     
( m7 N5 u8 V3 L# I4 B2 ?  c! t  document.sform1.chineseid.focus();     # S( a0 E9 S' Q/ y
  return false;     
6 j7 X: u. W* }# }- A  |7 h7 n- ?  }    - d" E+ ^6 h( Q/ i
password = document.sform1.password.value;     
- N0 z! C) V% J+ Z2 F3 ?0 H if (password == "")     
9 ]4 J+ s7 H6 Z0 W8 C2 f8 d  {     2 {* G5 N+ g  R5 O# S* o
  alert("请输入登陆密码");     
+ x5 Z+ ^& i; l! B8 Y3 W0 ~  document.sform1.password.focus();     
- Y. z- [& z! p: y+ A  return false;     
- L$ P' }- ?+ D& m5 I/ Q1 r  } * b2 M! R" g( q/ `2 y; M6 L
password1 = document.sform1.password1.value;     * i5 r( G5 _& F0 h
if (password>password1)     
3 \: h) W9 a2 ?- T  {4 a5 c' d( d& V- R3 l
     alert("重复密码与登陆密码不相同");     ' `- }8 K* A3 g8 b. N" K# \
  document.sform1.password.focus();
5 N$ g8 }! Y5 s( Y" c# ?8 g                                document.sform1.password1.focus();     
" R) Z  P& c- ^5 v  return false;
0 a8 _# V, K2 O* R  f6 Y  }  2 ~1 l1 p5 Y, a7 q: F( K$ Q  I
if (password<password1)     ' J1 S; R4 {- x! v; }( Z4 Z
  {% b$ u5 P5 m/ @
     alert("重复密码与登陆密码不相同");     
  X+ F1 m. g6 d7 d6 C1 x! u: g+ E  document.sform1.password.focus(); 9 x+ q2 j! X  w5 F3 B
                                document.sform1.password1.focus();     0 k' a$ f# j; j& H/ F
  return false;
9 r7 M! D) v! s2 x/ A: H- F  }
4 _2 {0 L' n& k7 O7 W3 H if (document.sform1.email.value == "")     0 ?7 D: r. c5 n2 y
  {     
' v1 @( e, u- L* \+ Q  alert("请输入您的E-MAIL地址");     
7 v1 o! i4 d$ W  document.sform1.email.focus();     1 ^7 _; Y9 F! w$ _  ~
  return false;     
8 e# l5 T% r0 W3 T6 x  }     
& `3 f- n1 o$ U* [; Z      
6 ^! i0 r. b' b: I% v email=document.sform1.email.value;      5 B9 Y% j2 R: x; b; D4 x
emailerr=0     
/ T5 S$ q! f7 C3 g7 g, t: K for (i=0; i<email.length; i++)     ! d2 S1 U3 H: n# e3 z5 W7 j
  {     ! l+ ~  ]) _, z. B+ s6 h1 ^! u! A
  if ((email.charAt(i) == "@") & (email.length > 5))     
: i2 `- l' w# z- X2 h   {     7 ?* I) _7 b' M- z; j! a
     emailerr=emailerr+1     * R5 v, O8 Q9 ?. {# X( ]+ j4 s& o
   }     1 c9 S; B( w, C/ Y6 K. ]: L! @
  }     7 e% k, d" x- s1 ?
if (emailerr != 1)     
8 a. N( P& v3 O4 K6 b* i# N  {     # o+ i* S+ k7 |0 q
  alert("请输入正确的E-MAIL地址");     
+ m8 F8 o, L# n7 {  document.sform1.email.focus();     
/ K, \( R( ?3 K! ~. z4 d( X  return false;     
" a5 X+ q: c# ]7 P) v  }           
' `$ B0 ?; R8 }1 m0 \- r  
' ^/ T: n/ v6 X0 q" R if (document.sform1.checkask.value=="") 0 H' K- d+ ~) G. V/ |+ f
  {
8 r. e4 p, t6 [0 A   alert("密码提示问题不能为空");     
' K1 B& M( e* d   document.sform1.checkask.focus();     
# I: @: u$ ]) ~% M' \' S0 ?% H0 k   return false;  ) W/ e% a5 A" W" N+ a& P% n2 K- h
  }
( o" B' ?' I  T8 ]+ X' [6 t- ~ if (document.sform1.checkans.value=="") & k7 P* O! v& L# s5 E
  { 5 \$ z- i, x* |' q# D
   alert("您的密码提示问题答案不能为空"); , A, L7 s2 c/ _5 a8 L
   document.sform1.checkans.focus();     0 ]: U5 {7 p* Z3 ?" Z1 d0 p6 o8 v% R
   return false;  
) O; T( s5 B" X. T9 |( j  }
) q  f& O  q+ f) G( _6 v0 \: t return true;     
& n  E3 G5 z1 g. s6 {1 b3 f, G     : _3 l0 X7 N2 Y
} 9 H+ A: h4 n, ?& I
</script>

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