返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
- N; J3 p  J- ~2 r  Z<script language="javascript">     
; ]1 E" u% _  N. l' v6 n( B  N: {function IsDigit(cCheck)     " }& b0 h$ M4 V. D' k/ {; p
{     : L6 }+ s/ k) f& Y+ Y
return (('0'<=cCheck) && (cCheck<='9'));     # ?0 f( Y/ A: g- v8 k
}     
# n; k" T( Z/ Z: e8 L$ q     2 n/ T; {. z; u  b7 t! m9 W
function IsAlpha(cCheck)     + e. l- j8 Y$ ]1 T, Z5 b- O
{     
9 g6 |& H. p( p2 G& y# y return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     - A. ^0 w# N/ w4 H: U  }7 ]
}              1 ~0 u5 j( P+ Q, u2 h
      
0 q: V- g2 C' Q5 cfunction IsaNull(cCheck)          1 @$ m0 r& h4 H$ e& _
{         
8 `- X" `( ]2 V7 H: }+ @- m. m: R return(cCheck != " ")         7 G3 I6 }2 B2 b2 S6 F8 a2 L
}                               3 C8 r9 U8 t& @  g
        R% b  M1 n* h" a( e" ~6 j
function checkform()     ( D) b' j  d+ U
{ 1 T9 K9 N6 w3 ^
  id = document.sform1.id.value;     
: m  _% {% N2 w; s if (id == "")     
$ ]# U0 N, L0 g1 H  M& d  {     ) t9 K9 }) ?2 V& g
  alert("请输入注册名");     6 Q) F0 \* J5 k0 T7 j7 s* u( I/ K
  document.sform1.id.focus();     , L% S+ y8 W3 l+ a' q
  return false;     $ D& h+ j! s+ w
  }     
' r7 C* c% M0 k0 q     
3 O" |2 G9 B9 L; B% ? for (nIndex=0; nIndex<id.length; nIndex++)     ' e2 w& t3 T* |" D
  {     ' e0 v& u! U6 Z  I+ I  _
  cCheck = id.charAt(nIndex);     ! |" X0 w  i  A1 e8 n
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
4 y3 N& k/ e7 r2 B! b   {     1 y0 U+ P1 i9 B
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
# y3 a! f+ E- x* `5 c   document.sform1.id.focus();     , t2 ]) G0 N4 y1 j, V! O# _
   return false;     
7 t3 [' e9 E! G4 p  |* I% A' l   }     
( U6 r. a4 k9 y! G) C0 U  }
" g9 `. y; {6 B  f0 ]+ ~  chineseid = document.sform1.chineseid.value;     , L9 j& R/ I4 |! z9 N9 t
if (chineseid == "")     3 Q% P- o( d' O, w  Y) U
  {     # Z- f9 g4 @1 b( P/ g
  alert("请输入中文昵称");     8 Y: L' V: h* c
  document.sform1.chineseid.focus();     0 N1 C( a9 c0 ?) b# z& j
  return false;     : w9 f6 P5 Y; p( O* u) E
  }   
, g; p. B: f' W, m. F; Q+ S+ ` password = document.sform1.password.value;     / x( }0 z2 j* a: k' r! M5 G. G
if (password == "")     
% a) Y+ A( F  m; r  {     1 P4 j( x/ P& O* c6 J
  alert("请输入登陆密码");     " A& t7 h! F: }- g5 e
  document.sform1.password.focus();     
* A, \/ `$ _5 j0 ^  return false;     
$ g$ u. B, H: \7 b  }
, ?3 R% I+ S: L password1 = document.sform1.password1.value;     + w9 ?( N( B1 k. [
if (password>password1)     
1 U$ c7 u2 ?  s+ ]' k" v  {
, c9 O' k; u$ x1 d8 }' Q+ T" \     alert("重复密码与登陆密码不相同");     ) c; E9 X9 A) g$ w
  document.sform1.password.focus(); " z- W0 {- R2 ^# \' Y
                                document.sform1.password1.focus();     ) R7 V5 Z2 q8 @* ~. [
  return false;
% L1 n" h' z2 D9 F0 g  }  4 P) n0 s' c' y" e) O9 B. k
if (password<password1)     
. }- M7 Y, }4 X% n; P$ \$ ]5 m  {0 K" b* n% m; Z$ i/ ~. ]" o
     alert("重复密码与登陆密码不相同");     ( ]8 G, r% E: s
  document.sform1.password.focus(); ' k/ W; g' a: e7 a& ]2 o' G
                                document.sform1.password1.focus();     ; F8 Y; n/ Q) y. X( O
  return false;2 e, D  U, l0 N/ _; m
  }
4 J0 h4 G* I" E( U0 M if (document.sform1.email.value == "")     
+ T+ j5 v5 {$ X9 U# ?$ h  {     . N2 `. S2 ~2 P( \- a. G
  alert("请输入您的E-MAIL地址");     % T$ E( J" f; T  c
  document.sform1.email.focus();     1 W/ |+ t7 ?8 f2 @. q/ |( w5 e- P5 ?
  return false;     
1 X" h% M# Y& R  }     
1 N2 K# B' t* d  r9 \      
, t2 H' S8 T2 Q: `0 P) L( t email=document.sform1.email.value;      3 Q0 m: ?- T' R; o/ N: T
emailerr=0     
) a6 f; P4 v' n' }6 Z7 G# w  K for (i=0; i<email.length; i++)     
; r( ^* t2 \- {4 J% v5 H  {     
  z- \2 s$ v, I  if ((email.charAt(i) == "@") & (email.length > 5))     # d, }: |1 S; J& G) e  Y
   {     
3 B# q4 e# |8 }) t# y- R     emailerr=emailerr+1     
& s/ S' v. R; C9 J' u# T   }     
+ Y1 o6 j  q$ ^8 Q2 |. Q  }     : _, Q' X) V" N2 s" v( |# e
if (emailerr != 1)     2 d! z4 ^' F, a% w( l3 z
  {     6 `( d& C- Q4 \: u% B. t% A8 k
  alert("请输入正确的E-MAIL地址");     0 f) V; A0 n' S; s
  document.sform1.email.focus();     
' }" H5 T" r) ]* }1 S+ A  return false;     
' d" `9 |/ N" \9 C" i  }           1 z4 \7 H3 i5 D7 o( z
  * M4 t0 P: N8 B3 Z
if (document.sform1.checkask.value=="") 9 t6 {/ A2 H7 D+ _4 a
  { , A9 T5 }. I8 N# P. v
   alert("密码提示问题不能为空");     1 Z8 z5 `7 \4 L$ |8 ?3 n
   document.sform1.checkask.focus();     & W- x- G3 c% J0 l' I! b3 y
   return false;  
9 [  D. u$ I9 s6 X  }
" O& E. z  r( ^( R; A/ Y9 n if (document.sform1.checkans.value=="")
, Z0 l- f$ N4 q" ]' o1 B  { ! U3 ]& r/ }# w8 `3 I4 {8 a& f, F
   alert("您的密码提示问题答案不能为空");
/ v/ t/ F. L8 @7 F2 K: ^- s% ^   document.sform1.checkans.focus();     
7 J- d- q/ i6 @+ H5 H   return false;  2 t* _/ g3 d( w6 ?% S/ q
  }
9 A' D7 p& U3 o2 Z8 w+ J$ p return true;     
# \# q2 K5 J7 s) g' G     
) L+ V* h# p5 ~2 S} 5 w/ V7 g% e# ?9 R3 D
</script>

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