返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
' D: v; Y2 R) p7 t  f; t, g<script language="javascript">     : i9 R$ R+ f6 T3 D$ @) P
function IsDigit(cCheck)     
/ t" W1 s1 S& W2 D1 ^. \ {     
5 Y- E, o. G4 q/ x2 y; P return (('0'<=cCheck) && (cCheck<='9'));     
1 O& ?4 \7 `; w/ T) M }     / T! q( E8 b/ D) N4 D+ u9 R
     
" s( D3 f$ `' G. Z* Jfunction IsAlpha(cCheck)     
7 k9 Y( i. [" B0 T7 | {     
% f" _+ M+ M! i" k* ^; h9 Q return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     8 m" R) a" k9 L( G+ }9 I$ }8 W9 Z3 M
}              
2 u& y2 j" d9 C/ @! m. |! \- _      5 @9 q& x( ~( C) M5 h
function IsaNull(cCheck)          5 s$ M( H/ u- D' h& s
{          0 E' F$ M4 c% K9 Z
return(cCheck != " ")         
2 j3 f5 A0 f- x$ i }                               ; Z5 ]5 q; [$ |9 g0 c8 S7 P
      
1 x2 {; q; Q5 y6 u, `function checkform()     
* e9 A) f& o4 s3 i3 w{
' L3 c  O! s/ i9 E6 ~  id = document.sform1.id.value;     
' I9 [( F0 c  z* L9 f+ m if (id == "")     ( J8 e# v' O$ z7 C
  {     : j0 F8 N5 n- T& j" y% ]
  alert("请输入注册名");     + w- q4 j3 a4 x, Z" |+ X
  document.sform1.id.focus();     & E3 N8 t4 N" c  |4 F
  return false;     
3 y1 {( E9 L+ [5 T/ Z% E8 w' F- L  }     ( f- n( _; S  u8 ?8 W
     
3 I( M% g6 l& P/ i1 }( q for (nIndex=0; nIndex<id.length; nIndex++)     
0 a" ]* Y* [* }- g7 t% ~  {     3 Q6 l/ X/ P9 s& A
  cCheck = id.charAt(nIndex);     6 E  t( J) g& T1 A
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
5 d  t8 m0 Z3 w6 m   {     $ Z' x7 T; r5 e& b3 l/ U
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     9 H  q) d* g% h- p1 K( m" ?
   document.sform1.id.focus();     8 w9 i. j/ E+ S5 q
   return false;     
8 i* W, W3 j6 p, P* ^3 l   }     
4 S1 [" @+ O; `' |* n0 `  }
* I2 T% K/ D; `5 H2 n  ~0 T  chineseid = document.sform1.chineseid.value;     2 F$ N3 w0 F; {$ R1 w* c! }4 |( ]
if (chineseid == "")     * \8 ]7 b& m  P- \
  {     : t* F  I  g% J
  alert("请输入中文昵称");     9 N2 s/ }7 C" U
  document.sform1.chineseid.focus();       X) e: h. [  M/ g) U. F- l
  return false;     
6 r3 w# ?3 u3 |' L- g  }   
4 L( Q' k0 \$ u- @ password = document.sform1.password.value;     
- n: O0 b; r5 } if (password == "")     
+ n$ H, l% K+ V2 O  {     ) H  ?; y9 p. B5 |# V
  alert("请输入登陆密码");     
% z; S1 U6 [  T* X1 Q! X6 o, Z. M  document.sform1.password.focus();     
) n5 `2 `0 m7 [3 K" e# J' H  return false;     
" s( r' g. [! u) K; Y2 r  }
& n6 e4 A, Y, a' _6 {: _& ` password1 = document.sform1.password1.value;     
/ W% ^" v) p9 a: u. h. y if (password>password1)     ) N( v$ Y  v% Z( @
  {
1 N: n# R2 h' K6 r     alert("重复密码与登陆密码不相同");     
9 t! z) x$ [! O( W  document.sform1.password.focus(); $ o2 g5 X5 z$ V1 L
                                document.sform1.password1.focus();     
" j# A- @/ O& p; }  g  return false;9 F3 n9 w* T0 i8 s4 P
  }  2 p- f0 }3 b" {# ^( b1 l& `
if (password<password1)     
6 M8 R+ k  W$ A0 j& V  {( i# y# H: ^7 ]$ w9 ]
     alert("重复密码与登陆密码不相同");     
7 V% L2 p6 X7 U4 i; n  document.sform1.password.focus();
0 S: t0 u& T5 \% v, i- K/ S8 G" j1 F                                document.sform1.password1.focus();     
& L# i9 r' i& V% h  return false;% K) o4 x4 S( {# t- P
  } 8 y* h( W. y  G7 d
if (document.sform1.email.value == "")     
8 U$ j2 e2 N3 M  {     
, W  \0 @7 z. q8 F* N3 L, Y7 G  alert("请输入您的E-MAIL地址");     . Z# @# v7 a- {& H) H- ?
  document.sform1.email.focus();     8 L# M+ S0 j! |) K% M" `
  return false;     
4 R. B9 K7 J! C  }     
1 Z% L: e. _; Y9 v      % S3 }; W( D% m* L1 [
email=document.sform1.email.value;      + ^7 G2 `9 D. ^- V4 h# n% I
emailerr=0     " M$ z5 U/ P2 J
for (i=0; i<email.length; i++)     # M6 K( e6 Q; ^. W5 ?; y( a
  {     
9 k$ l0 X& G3 [& o2 u: [2 {4 E  if ((email.charAt(i) == "@") & (email.length > 5))     - h" D/ X; t/ ^
   {     
- W" ~6 |4 s3 u7 ^% k' q     emailerr=emailerr+1     1 }% H: z" N- V# @
   }     
3 N1 T9 H: N3 F8 C) h7 Y; p  z  }     7 s6 M0 t- H3 x: n& L
if (emailerr != 1)     4 R( P! F, c9 b% v
  {     5 T3 A: ^! t/ b& j5 B$ i
  alert("请输入正确的E-MAIL地址");     
* ~7 k) E& I( f& g  document.sform1.email.focus();     ( I/ D0 r9 o' ~5 w% l/ K( v
  return false;     5 Q  K3 q" u$ ~0 @
  }           : B+ C6 v) f6 b$ {, C) u
  
$ n5 R; O! a7 m, }" ^ if (document.sform1.checkask.value=="") 6 r5 f, C  v7 E% \6 l6 p1 R
  { & O9 `4 x7 l( U" Z: O
   alert("密码提示问题不能为空");     
  y4 i6 t- S0 [   document.sform1.checkask.focus();     6 l( e; U4 G/ I" N
   return false;  " v" Z: F3 Z& ]  c- d  p3 \
  }
2 a8 v. c& F& F7 q' `; ]/ n if (document.sform1.checkans.value=="")
1 G' |7 R8 X0 u+ Z% N$ X  {
' e, c6 d, v, G  f- H% k6 S; O   alert("您的密码提示问题答案不能为空");
& f% U. Y8 p7 k, G- P3 W  R& E   document.sform1.checkans.focus();     * q, q7 O' X: N+ u5 @
   return false;  
% x+ I' j8 J) d8 y  }
' k. W/ [7 N  R2 F6 _0 o/ n4 u return true;     
0 ], w& I! {: _6 z     
# \) j% j' }4 X# a; k}
0 k& ~: F2 S8 y0 K, c: R$ Q3 K</script>

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