返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:  J1 ]" x) Q! z4 m7 A9 s* R
<script language="javascript">     
4 h7 s+ I, P/ ~' r1 i% o% kfunction IsDigit(cCheck)     
! J8 p* p$ Q1 ^ {     ) \4 n4 i/ S5 t) l3 o" |$ q
return (('0'<=cCheck) && (cCheck<='9'));     
: \* U2 v2 @0 t }     # @' h& ?. x& U, `
     
# S1 {5 t  a" S/ U: q5 afunction IsAlpha(cCheck)     
! _. w; B7 b' x( t/ w. F {     - |7 \/ ^2 q; V3 p5 @; b  S! v
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ) X- N+ J$ V7 F. `. a1 x4 @7 _2 D) Q
}              / O: B& a7 Y" e( n
      
" P, V# G9 n' afunction IsaNull(cCheck)          3 @0 b+ c: T6 e2 a* E
{         
! j4 g* a% v8 T. @! Y# B return(cCheck != " ")         
  _# V: p2 j+ H6 u8 M0 Z6 q }                               # W7 c, M0 ~) m; z/ d1 {
      
; l* \  n9 z. y: t; g* _' U8 v  Lfunction checkform()     0 J+ M5 T, I, c3 [% a& T' j
{ $ W1 |0 ?8 d8 w
  id = document.sform1.id.value;     2 f' R5 u3 H: a; h$ Z* @
if (id == "")     
- m6 h  j% F+ O! {; Q1 {: w  {     4 d3 e. q  q; J8 r  T
  alert("请输入注册名");     
$ L% c! T# l* ]- A* E5 D+ g% R# e  document.sform1.id.focus();     
9 c/ [# X/ V2 T  return false;     , G, S# L( C6 D
  }     
( Y4 T3 @. r8 Q8 K$ W. H2 n+ E     0 D/ E. l1 Y2 g% k7 b% ?3 r
for (nIndex=0; nIndex<id.length; nIndex++)     ! V& Q7 s; r8 ?& J0 f
  {     0 \5 T) d5 Y* q5 _  l3 }1 z
  cCheck = id.charAt(nIndex);     
) k. e2 J# ?$ {8 `, Y; Y1 Z7 i8 N5 C) `  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
' s; P6 W( G/ k8 u( J' I: c   {     , @9 e- }0 J' |( `& v
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     7 S4 N& N8 q* B; h
   document.sform1.id.focus();     
) {  q5 j) {: t& U& G0 e# o- S2 j   return false;     0 t0 u2 }" A; s, ~" g4 d2 e
   }     
7 P# ^% t1 _4 H) R4 P, V( T  } 4 X+ m5 a( p  |# [
  chineseid = document.sform1.chineseid.value;     ; M- g, O5 r3 E1 B5 y' j2 e9 W
if (chineseid == "")     
& J9 m% v; j) h+ W2 g" }  {     
$ v8 p0 s# `) H/ g; l  alert("请输入中文昵称");     
( g. ?. L/ [  R( j  document.sform1.chineseid.focus();     
2 a6 S# \- K, o/ I  return false;     
& P- u. z1 Z. X- \9 {( ?7 ]  }   
! D5 r9 ~8 x+ ?: E2 y+ t5 { password = document.sform1.password.value;     6 w. H4 e$ O+ ^0 m
if (password == "")     2 j% V. }6 L& j
  {     ) v, z% K: e5 g1 U) G/ ^
  alert("请输入登陆密码");     # k5 E& N- z/ I( ~4 k5 s# V- Z1 m. T9 [2 _
  document.sform1.password.focus();     
& x" c1 p! r7 v% C  return false;     ( l: w( y9 Z  Q9 D
  }
$ x1 t3 v- n+ z) j% [ password1 = document.sform1.password1.value;     
2 d# _* f+ j4 J4 H( ~; \, k# y& w if (password>password1)     
5 ^, M9 w; m8 f/ O$ f* j/ O9 F  `+ o  {$ k: j! F1 O1 R% S" F& M
     alert("重复密码与登陆密码不相同");     - N+ u" E0 ^& d* O7 K8 i! {% J
  document.sform1.password.focus();
- c( r. R5 w3 z) `1 ]# f4 L- l                                document.sform1.password1.focus();     
+ |' u& t3 v) i: _  return false;. j6 W3 ?0 Z! j2 `4 t8 \: D% c: X
  }  $ e; `" I7 C9 m/ b4 W- m
if (password<password1)     
0 m5 F: k" l8 c' l  {
3 g. y7 Y  o5 D     alert("重复密码与登陆密码不相同");       q5 \$ ]* K5 B: }( i! m% l3 s
  document.sform1.password.focus();
( N6 X  j( }8 K6 L" _$ {# d$ G                                document.sform1.password1.focus();     ! s8 z) n' k0 L$ h9 H1 S
  return false;
1 j% j/ F, S( d/ y) @9 }; ]  } 9 `; @* v* I, f: K% A  p, k# k4 t( }
if (document.sform1.email.value == "")     
- z' ]- n( m( K6 w) z- F  {     
1 r8 d6 h3 Y6 e  alert("请输入您的E-MAIL地址");     ( G, ^6 Z+ E$ D
  document.sform1.email.focus();     
6 j7 V5 S9 B, H  return false;     
4 U$ d( p/ f/ J0 ~) U+ ~  }     2 i  Y2 u; r) E0 H3 z2 t6 W
      
# K0 h  U: e7 a& F* y2 Y email=document.sform1.email.value;      
  O( {: A! w' @, m& y2 r* f emailerr=0     
' A: f, R( }- M2 r  l* o for (i=0; i<email.length; i++)     " F3 L- I6 I) b' g5 N" H. D
  {     
. g' b& Q; ~& G$ a; L  if ((email.charAt(i) == "@") & (email.length > 5))     
5 L' m6 F7 Z6 i( u* N   {     
6 Q+ f. O- y4 r$ v     emailerr=emailerr+1     
! h4 W& u5 L6 e6 b2 @6 |   }     
+ K6 _. ^# H; C6 X3 t( V/ h  }     
3 F0 a0 d/ V) P0 x2 a if (emailerr != 1)     
, B( T4 p2 ^; `3 N9 L  {     
$ G* u7 H: G' D2 t$ B; q7 S2 [0 W  alert("请输入正确的E-MAIL地址");     
4 ~" U3 ^% Y. J7 j; n  R8 W* C" Z  document.sform1.email.focus();     1 P7 E+ |% S$ E* U
  return false;     % P; N1 c. R9 K/ P  {
  }           0 w( N7 S$ r/ X3 P2 X* U: P
    _. G$ d& T9 G
if (document.sform1.checkask.value=="") 0 D9 t* L/ |/ r6 k
  { 6 d" N& ]  C0 e0 y
   alert("密码提示问题不能为空");       }7 m8 z3 ?, _2 D+ V
   document.sform1.checkask.focus();     ( M% m' e8 L, t/ p1 N& T9 Z+ V  r
   return false;  
9 H, l, @. I' |1 O! ~) \  } ( D9 o7 P  J1 J* g- U! Q
if (document.sform1.checkans.value=="") # o; m6 y* [6 k% ~
  { # V& D  j; x  C  M
   alert("您的密码提示问题答案不能为空"); 9 t6 z# I7 x7 x2 ~% `& l# [
   document.sform1.checkans.focus();     
5 r# N$ p/ p" n) d* k; Q   return false;  
' P9 G: k! A2 F3 g% p! |# \  }
" j' p" i1 g: F% `5 Z0 d return true;     0 U! ?) o9 ]' Y$ Z
     7 |- ~" p) @& S9 `1 Z
}
+ x1 I- R' ?# F' ^</script>

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