返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:0 ~. x0 E8 z8 G7 Z
<script language="javascript">     4 h8 Y3 Q( P* L# `6 R
function IsDigit(cCheck)     & U+ }) ?$ H) D: s5 @  e7 {
{     
- \9 q1 x; V, u- g$ a2 v9 M return (('0'<=cCheck) && (cCheck<='9'));     ) m0 m3 J7 C3 j6 h
}     
1 y" W+ O, @! G     
  g) S+ H8 T  b. c$ U! }function IsAlpha(cCheck)     
8 r: W6 }" ~9 v3 C9 A {     2 m* @! |* H( r$ r  I& \
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     : D* D7 i3 P7 l3 ~! F1 p* Z
}              
& U! h: q. j) V! x: j5 C8 `      5 D7 }- q1 B5 v$ ~6 v
function IsaNull(cCheck)         
6 o- K  [/ j' e' z/ Y {          7 a1 v7 Q% s' t; Y" c( v( J! u
return(cCheck != " ")         
7 ?+ F6 j+ [% J% L; v# Y6 P }                               5 D5 L" p7 ^2 ]" i
      
; Q. u' S, p- y5 {6 Z! R& s% o5 H  Rfunction checkform()     
% @: J# a, K" r# @4 J; i{
9 \$ F- m! J( w4 J$ U5 X  id = document.sform1.id.value;     
3 d1 K. k% o8 a" G0 c3 S! |- q if (id == "")     ; c( K. E' \8 P, [8 A4 L. Y
  {     
! N9 N  Y/ ^6 D  x6 _) g- w  alert("请输入注册名");     " c& j" V2 B6 P2 k: @0 d  {
  document.sform1.id.focus();     
% b9 m; [, a; G5 `) a( P; w3 @( f  return false;     + t& W* u& S# m! t; F
  }     
, ?: y  E; ^3 V1 |5 K     
; ]9 G2 @2 d& @$ t for (nIndex=0; nIndex<id.length; nIndex++)     
% [1 ?" g* {: [+ U  {     
. K$ C0 C$ M% z7 w' \* m6 h  cCheck = id.charAt(nIndex);     + I  ?4 A/ L( }) C6 u
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     5 ]" V  o# T2 Y( Q" L
   {     8 @' |) h+ E. g, q/ X
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
# r- ]" P+ b0 ]7 e0 q   document.sform1.id.focus();     
2 r7 [* s: w, [/ U! H   return false;     
' q0 |, e1 h: ^" k5 Z% T   }     ; n/ l, v& e5 P: U& S1 _
  }
' }+ U5 F' R' a% f! [6 z7 b  chineseid = document.sform1.chineseid.value;     
' k$ ]# X' k3 _; g if (chineseid == "")     
$ I2 A5 u9 X% _6 [  {     
8 Z% n: I7 w" z/ X  alert("请输入中文昵称");     
+ U( o) @# ?5 \+ Q) O# E  document.sform1.chineseid.focus();     # i5 F3 A  O4 O0 k' v5 U$ Y
  return false;     
( W4 |4 n2 d. u. ?8 x7 i7 l  }   
: d3 V2 T1 U1 D4 M5 z password = document.sform1.password.value;     
( `3 Z4 t$ w6 b1 [ if (password == "")     ' m' b) J1 l0 D" X* z6 P' I
  {     ) h& n$ }9 Z5 t5 i. T
  alert("请输入登陆密码");     2 {4 m8 |2 d( D, X7 p) B# g
  document.sform1.password.focus();     
3 @# G" N1 j( O) o7 H) q$ r  return false;     
/ C$ U8 t) z5 F7 [  } 6 B7 Q" b: I+ c% F( w! f  ]# m
password1 = document.sform1.password1.value;     6 A" l, C. A* z9 w' D! f! k
if (password>password1)     
2 j  F8 s" V: ]1 y; ?' A) d  {
; C. D: _! N; Z3 ^4 D; A2 i     alert("重复密码与登陆密码不相同");     3 w  g3 i4 V  a9 F( B  ]0 L
  document.sform1.password.focus();
7 W# ]' M, ]5 D                                document.sform1.password1.focus();     2 Z% U/ O) \" v+ G% O& W' G
  return false;
" n( R- E4 S; e2 D# l5 p- d- T  }  & u! Q$ s! Y( s) {$ v) j
if (password<password1)     
# S/ b3 O) f0 [/ B- D* ^, {  {% U3 F: b4 o2 l  H7 o
     alert("重复密码与登陆密码不相同");     
  a2 s. p+ @- _7 H; j# [  document.sform1.password.focus();
9 \/ Z3 ^" y; O( h3 T$ x                                document.sform1.password1.focus();     
) Z% I( t: k: T8 f4 i. @# [3 `  return false;8 n2 e1 b3 ]# F
  }
6 e% C( ]5 Y3 D+ e9 m# P7 g6 C if (document.sform1.email.value == "")     2 G) P. V+ }7 u3 o, M* `
  {     1 I! h5 \% f  Q0 v/ s  z
  alert("请输入您的E-MAIL地址");     
0 W* C: D  c; X& f5 H  document.sform1.email.focus();     
4 X$ Z% @1 l; K9 j3 ]0 l; v% t  return false;     7 t  k5 t8 d4 `* y) s
  }     0 K' @! z" r: X' m) y4 g
      ; y7 l0 \% `" E8 G3 ~
email=document.sform1.email.value;      
/ ?. b: N4 l2 B' E; ^( z emailerr=0     ! g$ B) i4 l9 V* h+ g2 R* I
for (i=0; i<email.length; i++)     4 T0 ]- i7 M) D! E0 P
  {     / p8 v( ~. N' k6 ?+ x; R
  if ((email.charAt(i) == "@") & (email.length > 5))     
' f9 X0 I, k, t% y+ V1 z) m; z  Z  f   {     " a; `/ L0 V2 V! Z
     emailerr=emailerr+1     8 z8 D' }! S0 A% Q1 n9 Q
   }     7 [3 E/ H( @* `  @5 F* u! ^6 W
  }     
7 j3 D  e- s3 `2 p8 S( Q  r! l if (emailerr != 1)     
& D/ N9 r( d; Q/ \3 W7 O  {     6 A" u0 f( K. i1 Y
  alert("请输入正确的E-MAIL地址");     ; [4 z6 W; ~1 B/ h
  document.sform1.email.focus();     
/ J, J& q2 Z; R: U% s5 E  return false;     $ K! F" G+ w6 f  }& q$ c4 J
  }           6 X1 f2 d- L: c( l: o/ f
  
: j. a+ K0 I% |  g$ @$ e' t9 q if (document.sform1.checkask.value=="")
: c! X- x' p& A8 T0 r  {
; S* L1 E( I( p+ J, B3 P& f8 F   alert("密码提示问题不能为空");     - y- |* Q" t* b  k
   document.sform1.checkask.focus();     . v, y# w% ~& J% Z' x7 d
   return false;  
  w2 |1 a0 N& j# P6 T  } : d1 r: L2 x, }1 _9 e
if (document.sform1.checkans.value=="") 2 k( `+ Y3 o0 H& j
  { * U3 N9 O  m; V. t
   alert("您的密码提示问题答案不能为空");
1 ?2 R$ r+ ?7 z6 U  `6 W5 y8 K4 D   document.sform1.checkans.focus();       i5 x& F  e! q8 l
   return false;  
# \- |& u) _9 ^0 ^: Q: Z  }
6 B& n8 {, r5 @9 g6 q7 N return true;     
9 m9 U: y, a9 i     
+ X- |$ s" D3 V) X) f# O}
, Z$ x, x, }2 Y+ Y$ `( t# c</script>

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