返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:2 q- _5 }8 {9 x% p+ E* Y# i
<script language="javascript">     , F: F/ ~& p0 n6 o" I
function IsDigit(cCheck)     
* X2 T8 J* A; ]; ]7 p {     
) m$ n7 n$ e8 X1 \$ W, [1 C" f& N return (('0'<=cCheck) && (cCheck<='9'));     ) L* q' @; ]% W( u
}     
7 h8 V6 o) p% O" \  W1 A7 J) [     % E) c" B, x  ^0 Q5 T3 ~: d% p# K4 i
function IsAlpha(cCheck)     , }- M0 z6 y) F: C0 `) B
{     ' ~: d' I6 `! U2 ]8 x8 C
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
+ O1 Z0 }, j9 N* W }              
) t/ [( s+ I9 o' I# I      * P* m8 w' m" `
function IsaNull(cCheck)          , h' P: e5 E: k$ U2 e0 _
{          4 t0 H& g* N# j+ A( k; f/ K
return(cCheck != " ")         , o# U1 g# \' g) `  |4 O% E; R! p
}                              
$ i. E0 ~( N6 e+ F- @) w' P, u: M8 o; z      ( G& I6 `. F" Z; Z1 ?
function checkform()     
& j7 I* S% ^/ k: o8 i{
8 q. T/ Y! ]9 M5 b' U0 _0 p  id = document.sform1.id.value;     
/ r% D  E# w! ?) k if (id == "")     / q4 c7 i& L+ W; g
  {     5 a3 D- Q, B0 b: u, [+ r
  alert("请输入注册名");     5 L/ p3 ^) g* c$ l
  document.sform1.id.focus();     # i+ O" G: ^# M. J
  return false;     ! v2 y" X& Z2 b' U7 ^
  }     $ w& v; |7 x4 e( Y$ n3 O
     
4 {1 ^+ Q  C, Y for (nIndex=0; nIndex<id.length; nIndex++)     ' K; y0 x* @. P5 _8 e
  {     / C! a- Y) p8 V$ U
  cCheck = id.charAt(nIndex);     
8 \% C5 n, C* j* w% I- J& D  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     2 q2 _+ v" f4 y
   {     6 \, M2 y7 y+ U3 a8 A2 A
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
4 s4 W& ?9 S% Y& A; y: d) z   document.sform1.id.focus();     2 t3 ^! R4 y% o6 ]
   return false;     3 l( u( z) p; O
   }     
: Z, P2 O; J" |% c; W  } 6 ]# A5 }6 c- k7 ~, C% W
  chineseid = document.sform1.chineseid.value;     
2 r8 A+ E2 l5 A7 o3 S9 z if (chineseid == "")     
+ M. c3 h- s" p, b1 R5 Z& E, B4 z! ~  {     ! x. C& }4 w6 s; {  b- C" E# S+ P
  alert("请输入中文昵称");     
7 g5 G! r% s; ~. F3 n  document.sform1.chineseid.focus();     
5 N" ]% p4 M  C" v+ k  return false;     , N. J7 K$ ~; o( a  f; x4 h! b/ S
  }   
" y$ q% @7 d+ W password = document.sform1.password.value;     
+ |" j3 z8 L) n if (password == "")     
1 j) h9 M7 `6 c  q7 o  {     
" C$ w- R" b. P' J) o% l  alert("请输入登陆密码");     , l/ k! e. t; a' u
  document.sform1.password.focus();     
1 b" ^: l% N; N; {  return false;     
% P% o2 T' ?; {) O6 X) c  }
# T/ N) {1 M* v( o9 P password1 = document.sform1.password1.value;     % S1 J6 H8 i- E1 X/ f: h
if (password>password1)     0 l, ?' K( j+ @6 Z
  {
4 X" a( j6 n9 V# i- b     alert("重复密码与登陆密码不相同");     9 J0 ?6 \* s# x2 K3 }" M
  document.sform1.password.focus();
+ A- L& b  k9 ^* N9 I9 _6 M! F                                document.sform1.password1.focus();     2 S4 M: r0 C* {) ~
  return false;
+ @2 r6 i5 q. `' ~  }  3 \: j* ~4 y+ N3 Q1 `2 J
if (password<password1)     # P3 W1 O% h- E% t% t/ o6 z
  {' r# P. `3 p6 `! [* W: A
     alert("重复密码与登陆密码不相同");     8 F1 P8 c4 X( l6 j& C
  document.sform1.password.focus(); - H; M) A! I  H% \1 u
                                document.sform1.password1.focus();     
" Q9 \7 J4 H+ G- {; y  return false;
% k8 x" z0 h$ A& J$ W2 w  }
/ p3 o% O) D  D6 F if (document.sform1.email.value == "")     
2 D3 v1 a5 j4 h: Q. v8 \0 D  {     8 j# P. L& r$ z( H% n6 c& G
  alert("请输入您的E-MAIL地址");     
6 {3 I! g1 H( L2 u  document.sform1.email.focus();     
. y) x& B9 u; `$ a: P/ T& y$ n2 j  return false;     1 p! `: x" u9 r5 X1 C0 K
  }     1 ~" u0 t* ^( r
      ) H. S7 I: E) ~+ [5 A, l
email=document.sform1.email.value;      ; K$ l3 b: _3 Y% B: Z* D
emailerr=0     
( e. a% i3 Q0 Q! f# |7 ?4 E4 D for (i=0; i<email.length; i++)     / n, o2 H  ~) H+ \7 P6 e* I
  {     1 N6 D+ W* ^% a; f1 j7 B
  if ((email.charAt(i) == "@") & (email.length > 5))     & P3 t% K# }. U5 {( B
   {     
! c% `2 p5 r( Y! E5 o3 ?     emailerr=emailerr+1     % e: p/ l  W+ M" w3 m# l* N
   }     
( q- y  K  I6 R& }8 g8 Y  }     
: O; ?4 i7 f# P; E/ x$ r+ o/ {! Y if (emailerr != 1)     
) J. z  I1 [5 p2 n: [9 N  {     5 _( D1 J( R' N" i4 W* F
  alert("请输入正确的E-MAIL地址");       g$ Q- P- R% H; M
  document.sform1.email.focus();     2 f! W( O0 G9 I4 d, z
  return false;     
6 f5 k  C# C; ?0 W2 o  }           9 S% h$ D9 I, g1 M
  
+ K. A% h7 C, d! G9 Q7 N; I! ] if (document.sform1.checkask.value=="")
; m  o( |2 I2 }2 B5 Q  { 0 x; p, V2 g6 r# ]  S
   alert("密码提示问题不能为空");     * k: o# G0 Y1 h9 Q
   document.sform1.checkask.focus();     
. p8 W) ?0 P  z   return false;  
. r1 A$ z! Z8 p5 S( |4 V! [  } + g1 `* k" F% N* C
if (document.sform1.checkans.value=="")
& g7 P1 ?- Z- q3 I5 ?' V7 B  { + c! J. s) ?/ F3 }% r! |3 A
   alert("您的密码提示问题答案不能为空");
3 a" @& s- o( e) ^   document.sform1.checkans.focus();     
0 p* t5 ~( C8 d: k0 Z* q+ D   return false;  
3 R2 l0 h: V1 t  }
( [2 d) }2 a" E* J return true;     " H& D" e% L" C! s
     8 r1 W! Z) @9 [( Y
}
/ p+ R' v; ]& U</script>

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