返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
9 V* X+ l& R3 y; E0 G4 e9 l<script language="javascript">     & H; @  x( L% t4 g
function IsDigit(cCheck)     
. ]0 o; t  _/ T- t) u% s {     8 q& L7 ^  @$ A& x2 s5 `7 ^
return (('0'<=cCheck) && (cCheck<='9'));     / m  q( l, i+ R3 E% y" [3 O
}     
5 z, S- }3 J7 X% P     5 w2 G6 P. E' U8 Q6 h# z) ?  e
function IsAlpha(cCheck)     * C0 X4 W* {! L- F) |6 O' n
{     
; N" G' F" U' q3 O6 u  ~ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     9 E  o8 E* n. T8 Y! b
}              
5 T( E3 L$ L! u9 S  M      & Z8 ]6 _# p5 s
function IsaNull(cCheck)         
( w& A9 m: c# O2 A6 b* M {         
$ H3 o& A" @( N" ^: p return(cCheck != " ")         
* |- S. ~, P4 G* v" @9 u  U, X }                               4 l( p9 D0 F8 Q  y) T  z6 q
      # U. a) ?8 U8 r4 l/ P7 {$ J3 F
function checkform()     % b( y3 P; o9 Z
{ - D& g) T6 N% Q* _  \7 B0 }2 `
  id = document.sform1.id.value;     0 I$ v/ ?/ U1 I. B: A" i3 e" P
if (id == "")     
& o. b7 G, V7 [: d! ]  {     
! ?, d, s3 _" Z1 {  alert("请输入注册名");     - H8 d5 w: j' A! g# y) U
  document.sform1.id.focus();     
5 d  f- P) z' v" T* S+ w* _( H  return false;     
! G  s) s5 m/ u) Z& \: Y  }     
3 J( j4 s+ j# l% A: W     
+ x. w2 m& G! C- g9 |) } for (nIndex=0; nIndex<id.length; nIndex++)     " Q8 c+ m2 K4 i2 r7 c
  {     
: [8 C& D4 f1 ~  A: @" @7 |* y3 l  cCheck = id.charAt(nIndex);     
3 m+ Z3 p& h% G7 |: W  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     3 u. E7 o+ M; m" f
   {     
% A2 I6 k' A- @0 ?4 r$ a+ S   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ! H7 y) i: _& O* R& o2 S
   document.sform1.id.focus();     % t# i4 W8 W3 G# r
   return false;     
, T& T" O$ D+ x4 y   }     
" C3 z/ x+ \& L+ W6 I  }
( `- V2 U) C6 y; c' q: _! a+ s  chineseid = document.sform1.chineseid.value;     
1 R. p3 G5 ~5 Q3 E6 k if (chineseid == "")     
8 O' J( q9 |+ u$ h$ G  {     
4 J6 ]0 j1 W- x1 v7 g+ M  }7 s( L  alert("请输入中文昵称");     
+ j6 X2 m- j+ `5 n" b/ O  document.sform1.chineseid.focus();     7 B- ?! A' h) N  P
  return false;     
) K" P7 L$ b$ X; b  }   
% @0 ]# W. t, E- p$ x+ p2 g password = document.sform1.password.value;     
/ U& G! Q, R7 j( ^) e" c- G$ ?1 u if (password == "")     
# m& i1 L( Y9 W2 N0 j" O% x+ l1 r  {     
6 f. I6 f# ~1 A1 H) X0 D+ n  alert("请输入登陆密码");     
( W: A' p- |9 u1 T  document.sform1.password.focus();     
5 ^' G5 O* V. n9 U& L+ t9 @  return false;     9 X" ^  L1 b( `( v4 ?7 @5 X
  }
, L% b# `, _2 {- L password1 = document.sform1.password1.value;     
/ ?3 G* |( [! c. j& d if (password>password1)     ; r% Q7 e, E" n( P- J: s
  {5 Z3 x/ \& q0 C, g
     alert("重复密码与登陆密码不相同");     
% T+ i# o0 Y) |' K# r' L; T: ?  document.sform1.password.focus();
  @% ^4 e5 x3 R; q- K+ {$ x9 v9 I& A                                document.sform1.password1.focus();     
( o3 X9 m% ~  L( X5 L3 d7 k4 \; V  return false;2 B% _6 M9 c/ j
  }  4 A' E5 q$ B1 M( v# U" i
if (password<password1)     
. T, W9 T3 K3 W  {8 J. F- ]9 Q( t! S1 u9 Q2 }
     alert("重复密码与登陆密码不相同");     / N( g" E$ p9 Y: A0 i- f) |9 I
  document.sform1.password.focus(); : l9 b9 G" F( ?7 `0 D* L8 x& }; q1 V
                                document.sform1.password1.focus();     
* U4 R7 D! [& r# n1 r4 ~" _  return false;4 V  k$ [) [7 g; b# n  [
  } ) ?1 a, V! }  {% l; E/ d* A# b
if (document.sform1.email.value == "")     1 ^" C) P8 r$ u, A+ W+ e
  {     
7 ]# L+ G+ i# A' m, J- K7 Y' f9 F  alert("请输入您的E-MAIL地址");     ; b2 r, {# p; z5 R5 v- v/ V/ b
  document.sform1.email.focus();     
& }" r2 f$ p% I$ Z  return false;     8 m5 L6 Z6 F7 @7 Z6 F3 m; e
  }     
% n8 m# p; V! I" J. X      
/ }. {; Q* m3 Y, A email=document.sform1.email.value;      
. _: T. m. {" A7 l7 J* X% L, L emailerr=0     
  m% g' |0 W3 T4 t2 R2 U) h for (i=0; i<email.length; i++)     - A5 l6 U& Z6 m
  {     . z, u8 R5 G: T9 r8 c4 k
  if ((email.charAt(i) == "@") & (email.length > 5))       a: ^# K! f- M7 a
   {     ; j$ f0 n; ^. C5 R
     emailerr=emailerr+1     / W0 k2 E7 b! ?' a3 H/ k! I
   }     
" E& m2 F5 ~  c# _  }     
+ V  O7 W- x- D5 ]5 j+ ^/ M if (emailerr != 1)     / e$ V/ F5 F+ a  S5 @2 F
  {     & B( D1 O" M- O% n
  alert("请输入正确的E-MAIL地址");     0 @$ @0 M: M) N( p6 z) u
  document.sform1.email.focus();     9 c+ W$ C8 E4 x3 A' Q8 C9 m* W
  return false;     ' S/ ~; O% i+ E" o8 G1 p
  }           
, `8 r( p" U) ~  
, @  P6 B! R; Q" p7 j if (document.sform1.checkask.value=="")
5 k1 _9 n- {# _5 b  {
) w1 x) y  m: }  Z3 s; L% g+ N) }   alert("密码提示问题不能为空");     
% J9 E; Z6 r. D0 X1 {7 ~   document.sform1.checkask.focus();     6 d# B. S/ \% m+ a& W* f6 b
   return false;  ; e6 p9 T1 w2 j/ P, t
  }
+ j. I( D0 h+ a& L" C3 `, T if (document.sform1.checkans.value=="") 6 O( y' \8 g0 |! }) Z- u: i
  { 0 N1 M; z  Z& x. s9 o5 K* G
   alert("您的密码提示问题答案不能为空"); , j2 m. i) Y) w1 s$ M8 ~
   document.sform1.checkans.focus();     
& q" h( @1 f. d- n   return false;  0 d! K0 }: f0 t8 u: I
  }" B; N' ]' u' e* G
return true;     
2 d5 Y, h5 T: R5 S! [     $ Y3 l6 |9 z# T6 b4 ]
} 7 w& I) T9 s8 Z6 ]1 f
</script>

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