获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:3 L$ o& ^/ s6 x% K
<script language="javascript">     
9 B+ |. y, k5 V  g( y* ]" Nfunction IsDigit(cCheck)     % v+ v# N: g0 V* g* c. R. z6 e
{     % F1 ?7 ~* L5 t, X
return (('0'<=cCheck) && (cCheck<='9'));     0 T+ }9 d4 k3 x3 f
}     
+ N. I7 {6 b* v2 X     + l! O: f3 Z- w1 O7 ]' e
function IsAlpha(cCheck)     
8 R+ U2 u" |5 V) ~* D {     / [  A) a! F# E! p
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     % [9 g5 Q# }* p
}              
+ h3 Q4 W/ S' \! c7 J! a; P      
5 o( F3 E& v' _) Jfunction IsaNull(cCheck)          # R* V4 L: N; }4 s9 y
{          " a9 A' ^2 |& M3 w
return(cCheck != " ")         
2 k) i9 r3 M! |$ @8 W+ }+ Q5 Q) { }                               - f9 C/ V3 b3 @
      7 u2 x2 e' p# |( I/ S
function checkform()     , P/ ], p( Q0 W$ @
{
/ W4 g4 b  d" ]7 z& P% L$ M  id = document.sform1.id.value;     7 g$ \, ?: ?$ V0 N& L# L+ P
if (id == "")     4 B4 s$ l) g  i6 j! L4 s$ |! @. k
  {     
' ?& A& c5 z4 i' W6 [) Y  alert("请输入注册名");     5 ?- l# @, y/ |9 @  s7 I. g+ x6 \
  document.sform1.id.focus();     
) N9 R( Q8 B6 f$ F  @6 h* `  return false;     
( E! f) a% R4 N$ O& b% `  }     
0 l5 j; ^9 y6 N/ H9 l     
' A$ m, R, [, ]1 p+ @3 n for (nIndex=0; nIndex<id.length; nIndex++)     0 y3 {9 Q7 ^+ l7 }: Y
  {     : t& r9 o* d9 Y  k
  cCheck = id.charAt(nIndex);     - h+ o# \' k7 h
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ! m2 ~- B$ g0 \* t) o" r4 P* D) @
   {     6 B. x7 V- j+ T! H5 `4 V  h# g
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     " D' P4 L; \- H1 B2 q' I+ R2 M
   document.sform1.id.focus();     2 o, a2 [& k" ^$ M. E, O2 a/ [: P
   return false;     & n' _( U2 l) b
   }     % ~2 u3 |5 p0 M7 ?
  } 6 `2 v, K" T, U3 q' i6 F+ P2 T3 d% V
  chineseid = document.sform1.chineseid.value;     
% A3 N8 g1 l; L5 ~1 l2 _+ y if (chineseid == "")     # l) t  E$ K" _- b4 O& _9 y9 N. i1 u
  {     6 H  a" f4 w& _. Q# ?- A. E, Y
  alert("请输入中文昵称");     
2 `6 t% E  h- e7 h4 n  document.sform1.chineseid.focus();     ' g( G& ^7 A. _; D  |
  return false;     + G7 E5 ^3 F+ q, y. @! O1 ]
  }   
1 h& U: O; g" x( b6 V password = document.sform1.password.value;     $ F  M+ M9 q/ A0 R
if (password == "")     
6 N( {' U, H  }  {     , T0 G4 N! m) e5 R; I9 ^
  alert("请输入登陆密码");     
1 O/ O! p6 i9 x3 X' S2 h7 y  document.sform1.password.focus();     
; o" w& @# q9 p5 H" `  return false;     
; }  U& w' }; m  } 3 c+ k. e, S$ J# z+ C9 Y( i
password1 = document.sform1.password1.value;     & h4 S* r4 B3 T( P
if (password>password1)     
& l) L  }4 P# {. P+ o2 ~& r  {6 r5 C/ r; F' k! l+ p5 N8 r
     alert("重复密码与登陆密码不相同");     
$ d* S+ `9 W4 @. ?! r6 J+ r" Y  document.sform1.password.focus();
. o7 t0 S7 C* j" y                                document.sform1.password1.focus();     5 T% {8 X1 M) w* `, U' d
  return false;' H; i5 `& O% `
  }  6 G9 B: k: p* j5 }
if (password<password1)     
) i% x7 A" B3 p8 B  {4 N& I! S( @) v3 i- m  o
     alert("重复密码与登陆密码不相同");     
( H8 X& ]. e, S; {4 N( P  document.sform1.password.focus();
& H1 v) h' m8 z1 Q0 e3 M                                document.sform1.password1.focus();     
* b" p( ]' X& J; R$ r, w% k  return false;
; V1 M+ `4 n8 t0 O6 S/ r5 H  }   w. W7 Z" B% y; H! t
if (document.sform1.email.value == "")     0 k% t8 ]; G/ \* ^. f- i. O. Y
  {     
3 x, I2 g. L; g* I* e8 I* l: J  alert("请输入您的E-MAIL地址");     
5 X5 v$ _2 A. T* A& z8 P9 a' W  document.sform1.email.focus();     + B- j2 ?) n" Q
  return false;     % Q" T/ F) ?3 S1 C9 i
  }     
' o$ A! ]/ U* t. c! a      
" O6 x) }) l; g! `9 Q: q4 [ email=document.sform1.email.value;      5 r  x6 i. R! t5 G! m0 |
emailerr=0     
2 P. B5 x* z5 ~/ Q% }6 W% e for (i=0; i<email.length; i++)     
. L9 b) Z$ B  t. b2 O1 r  {     6 R& n% i3 X% {( I
  if ((email.charAt(i) == "@") & (email.length > 5))     ; i) [" S, A3 n/ G' P0 _
   {     
' v& h: }3 r% ~     emailerr=emailerr+1     . ^2 x6 R. f. h: P. d
   }     
- ?: r" E4 K; _  }     
9 ?8 ?# ^6 O8 B( [+ L& ? if (emailerr != 1)     3 T+ ^. [0 G! _- M) o  X
  {     7 {0 s2 P1 u* R' _- |# W, g
  alert("请输入正确的E-MAIL地址");     
5 x/ ~5 |  ^+ j2 w% A: S: p) p  document.sform1.email.focus();     # O1 Y6 i% g6 @- F% X& b
  return false;     
' C/ z6 B9 f) l$ J! @  }           5 t1 S$ h. p& R: h+ l
  
9 R' n9 I1 b# D& x( s2 ?! h% L if (document.sform1.checkask.value=="")
4 x% F- M% x- h  q! c9 N  {
# K6 m9 ~5 f: i0 _3 w1 q1 Y2 f   alert("密码提示问题不能为空");     : w$ S  L0 G' D* Q: X* O
   document.sform1.checkask.focus();     , F2 |- |" T+ n, [
   return false;  
2 V# I! e/ J6 c. x& ]) S: F5 n- \  }
, o; D9 p/ c. ?$ }1 Z; v+ r& b if (document.sform1.checkans.value=="")
0 Q0 {. D" d# N. r1 X+ r3 i  { " z) n, G& D1 ]  @
   alert("您的密码提示问题答案不能为空"); 8 _. R& z. G# V' I9 [
   document.sform1.checkans.focus();     
1 a/ j- O4 g# Q( i0 t/ P8 z   return false;  + v) D, _8 c% U& |" R
  }- q% @5 Q3 b0 M$ D  b% \, D
return true;     
" c6 z3 s! }. F& m+ a6 R     
+ R) Z8 m* J* [}
& [$ B# P$ p# c: b</script>

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