返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
( H6 B/ Q  T: y7 x. K<script language="javascript">     * V4 n" Q' D. Q/ M+ B% T
function IsDigit(cCheck)     
- |5 n; ]8 R4 f. T, v5 a {     
8 O4 u9 e5 K" z" U9 e7 Q return (('0'<=cCheck) && (cCheck<='9'));     
. j; J& K$ `3 p9 {/ W6 l2 q }     2 h- F: K4 W& w3 |; x
     
1 D7 Q( U2 q1 Zfunction IsAlpha(cCheck)     
- g4 D9 r, t7 A4 U, S {     & s" L' [7 Q: {6 }
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
5 F  Y4 [: U, k3 A }              ' b  Q1 J; W3 r: K
      
$ v  ^! O% ?; v5 C. }8 ufunction IsaNull(cCheck)         
, F7 N3 O0 E0 T! m' @; q {          - Z- ~" s1 w! r) p1 |; F
return(cCheck != " ")         : [' c/ v1 G5 f# l1 F8 k
}                               * |4 J& ^& m2 O3 i4 S' s" u
      ! J. g9 F* o( T0 n6 U; `
function checkform()     3 H, o% u. `: n! k. ?6 ~7 ~! N& r5 \) D
{ 2 N1 c5 w3 E- N, y
  id = document.sform1.id.value;     
: ?( x0 ?7 p* [. P# C. D5 O if (id == "")     
1 L5 e8 Y) _* E2 ?  {     7 `  Y, g  u) s3 C
  alert("请输入注册名");     0 j8 R7 s( u8 G; V0 [
  document.sform1.id.focus();     9 \7 `  _7 O9 `$ H+ M
  return false;     + L% Q3 C) X0 j2 A
  }     7 H1 {- d: a7 C8 N( ?9 m( ^
     
/ Q$ ?8 T+ G: A+ U. F for (nIndex=0; nIndex<id.length; nIndex++)     
" a& o+ ~, K% B! n  b8 f, o  {     
3 M/ ?+ T' x# {" L6 d$ b  cCheck = id.charAt(nIndex);     # ]! `2 m; g- t8 r8 F% w, F
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
+ q6 f& K7 E; R1 I& n   {     
! I1 ~' `1 `( t+ Z   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
& Z6 e6 p5 g! v- K0 ~   document.sform1.id.focus();     
4 Y% o0 ~' j+ j$ `   return false;     
$ Y5 Y+ p2 w- H( G3 ?- `' P   }     
& p. m3 X( W/ u. F0 `  }   R  K! }! |5 ]4 e( M4 W, g3 ]
  chineseid = document.sform1.chineseid.value;     ; P, N9 B! n$ J5 r1 c4 p# R
if (chineseid == "")     
$ q. q7 N, n$ {7 b. k: W' x  {     
2 P* O3 }4 p4 m, }. p  E  alert("请输入中文昵称");     $ d4 K* ], O% L6 V/ N1 B
  document.sform1.chineseid.focus();     0 l1 i! X- F' O& ?, {
  return false;     6 g0 ~* ^# F5 V
  }    % W3 ^( ~6 H, F# J
password = document.sform1.password.value;     7 [& i" s' w9 ^8 M" B3 A6 A
if (password == "")     ' C- P3 \( m+ N6 i
  {     * T! K0 D# g: b; B; z
  alert("请输入登陆密码");     
* X' G6 E7 R. q, G: A' M  document.sform1.password.focus();     
9 D/ ?3 N0 F7 O7 T% I  return false;     
7 r2 c" R" K  K/ h# U9 s  }
0 Q: P/ k( O8 M2 D password1 = document.sform1.password1.value;     
+ f& s; g! i" b" {) U. n( E- k if (password>password1)     
0 M! S3 r* m3 v( P  {
8 A0 B, P$ \8 g     alert("重复密码与登陆密码不相同");     
+ P+ \% D0 s" _! S' u% V  document.sform1.password.focus();
( r& T. h" J2 ]: `3 Y8 s                                document.sform1.password1.focus();     
& O' m( z- T- C. N0 w  return false;
4 L) ]' @/ }, `) h, k/ `* W: E  }  
2 L/ E) f0 F( q7 oif (password<password1)     
; B! v) P: W8 o6 ]6 p! a  {
8 {: V4 P9 ^' t3 P. {0 G4 d) ^     alert("重复密码与登陆密码不相同");     2 Y6 i/ M) f/ c
  document.sform1.password.focus();
% D1 `  b# Q' I- F" n- G( m2 O" F                                document.sform1.password1.focus();     
: D& J3 {# Q0 z; i  return false;
  a6 \' l0 r1 {% A8 Q  } % s' V  J8 P5 }8 u0 m  X; e9 l
if (document.sform1.email.value == "")     % @# i3 V. [4 q  J8 I) G2 R
  {     
3 n6 O" y$ o! z* J  alert("请输入您的E-MAIL地址");     
5 I. V# m( l1 ?' Y  document.sform1.email.focus();     - A3 `5 P" v3 W$ f, W
  return false;     
) O8 q$ ]* y2 G# `8 ?  }     
8 C& w" o# u9 O. D" O3 M& I      
! v, R2 v1 Y. v5 x- S email=document.sform1.email.value;      2 ~4 [7 `. \* i  @  j4 o
emailerr=0     
; ^8 {" ^; J3 {# U! B for (i=0; i<email.length; i++)     
& L, q4 g0 C! f1 l. U  {     
8 D  k: \! y  X1 }9 b5 F  if ((email.charAt(i) == "@") & (email.length > 5))     # k: f0 N  l4 }+ I
   {     , o5 _& M- ~8 Y' M! i
     emailerr=emailerr+1     
* p, E  L' j  \& X; X2 R   }     
- d- h1 v* {0 @  }     
/ F- ]& x$ x' ~) t5 F if (emailerr != 1)     
3 I. _' {0 c- _* v. T7 s  {     
% D# s. V5 K% l* m2 S4 p  alert("请输入正确的E-MAIL地址");     
7 k" g. i8 `& d/ R  document.sform1.email.focus();     . Y9 H- F3 `# V6 w% e
  return false;     
% T" E$ Z- {8 X; x# M5 Q  }           
8 T; m% X0 ?2 b  
3 U$ g: z3 L7 D if (document.sform1.checkask.value=="") 4 h+ D# m2 @8 L# n  e2 }5 f" F6 V+ H8 g
  {
  L* f4 G6 R3 o% I* ^   alert("密码提示问题不能为空");     ( N, j% m3 T4 E4 {% R* ?
   document.sform1.checkask.focus();     
$ w8 W* _+ ^. V/ C   return false;  
2 J. S! @4 g$ E4 V, i. i. m/ H! G  } 6 ~" V& s2 V2 E. v! E. v% e
if (document.sform1.checkans.value=="")
' w& ~$ a; q) I  {
) O( q2 q4 U' G  f6 W: B) K   alert("您的密码提示问题答案不能为空");
$ y) F1 q; x7 ^4 i0 K9 H4 n   document.sform1.checkans.focus();     8 Y! B! ?, ^+ g) }& `
   return false;  
" q/ g/ j3 k4 V9 g1 w- X2 U* o  }
' i4 j% H1 I2 J- f. i* {" _7 [ return true;     * u% O" e: f5 c1 Z
     
; b3 x2 [2 p6 N2 \4 H}
, I# Q* V. p& T  X; p! o- `</script>

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