获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
4 M7 G+ @" z" \8 f& n1 c/ B<script language="javascript">     - C$ h) @, m  _' S+ j/ W1 U( f
function IsDigit(cCheck)     
. n" r6 c2 O7 O! g6 d {     
6 S# q9 b9 U/ L. I return (('0'<=cCheck) && (cCheck<='9'));     4 ]; z; o  Y5 e& P6 k
}     # S/ n1 |2 H' m7 l
     ! U) `1 f8 }7 r; E
function IsAlpha(cCheck)     3 O# F; |! `- ~1 y* B9 X' {( e
{     
6 V# W5 _. p: H5 f( ` return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     9 J& ?/ g+ s- p' f* Q$ F! q
}              
& t, Y" S1 S0 |2 S* U' k      
2 ~: a3 U6 h  w6 w& Ifunction IsaNull(cCheck)         
4 R/ U4 f9 N. ]/ i+ q) Z {         
, K' h# z7 {2 K* ]8 u# [: R return(cCheck != " ")         
0 I' F/ L8 d! s( p  Y% q }                              
/ x# X6 K3 h$ e1 z' X9 N$ ?, Y- s  q      ; g4 j- X6 r- [3 Z6 j+ r, E
function checkform()     
- _0 ^6 c( T6 x! U( m) V. q+ [{ ; Y. c5 u' h2 J7 \% `: ?* \
  id = document.sform1.id.value;     
8 g5 w0 ^. m5 l1 K' C if (id == "")     
3 H3 |; |' L, F1 o6 q  C- e  {     
! H: G) C9 V0 c8 `/ [" \8 v( c; ]  alert("请输入注册名");     
- D0 z" @0 K/ s- k! B9 @9 q& w  document.sform1.id.focus();     
' M# z3 o: W/ N, B6 V7 P  return false;     & _- |) K8 N8 t, \7 q# G2 m3 x
  }     4 M/ ~- v  |5 o, ~0 O& z$ i  P5 d
     0 L' ?/ H0 x& Q1 ]' u7 \+ x7 S
for (nIndex=0; nIndex<id.length; nIndex++)     # S( p4 h# U8 L; ?
  {     2 H8 W/ S/ e* u  O4 G
  cCheck = id.charAt(nIndex);     0 i( \2 o' C5 Y
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
5 v* a: G- e7 H/ s  }! m3 l   {     
7 D2 @; a6 m+ `$ b; J* j   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ! Q" v, L& z8 a
   document.sform1.id.focus();     * O; Z6 y9 v7 O8 S! c* H
   return false;     
  h. ^5 V& Q4 G9 ^   }     ' A( D: H4 R( y1 M  N& w2 L
  } $ o5 S8 I; T( @: W+ f1 ^; E
  chineseid = document.sform1.chineseid.value;     
1 f& P% B# T$ }* [ if (chineseid == "")     
8 y0 C, ^7 x$ [. }- q5 E( ?/ M  {     4 S; p# |6 Y5 o
  alert("请输入中文昵称");     ) d3 V6 D' i% b0 V1 ^3 B
  document.sform1.chineseid.focus();       I0 e" s3 @* w3 W$ d% |
  return false;     ! z: V2 o# K) B" O' U& E
  }    4 G  b4 e3 X) U, c
password = document.sform1.password.value;     ! V1 X6 H% A5 N1 v- g$ |4 q
if (password == "")     
, _$ j/ t  g% w! a* s: Q( N  {     
2 X4 `5 U( q% n6 V3 i  alert("请输入登陆密码");     
, T1 r3 B, `. x  document.sform1.password.focus();     
( J0 G, K0 E  x  return false;     9 k# Z0 f8 h( o; e7 z" [% p( V0 T
  } ; A5 [7 Q# r1 b! O( y$ D
password1 = document.sform1.password1.value;     
4 }2 H7 p3 ]4 u: z if (password>password1)     , P3 B; z3 b7 o- W# b
  {% @+ d5 d5 A+ l; f- G" U. ^8 Q
     alert("重复密码与登陆密码不相同");     
; l; {& l4 t- i' Q: v4 _/ _  document.sform1.password.focus(); ; \+ r  V5 k& m: A2 p
                                document.sform1.password1.focus();     ' Q' u7 Y; G, k; U  a
  return false;
0 P4 p4 h2 N0 G6 b4 z# Y. l' i( j  }    E" y1 {" r0 J) S3 D8 E+ G
if (password<password1)     6 X7 A( ]+ i6 w  M: m* M1 C# a
  {
5 Z& M" |+ Y. I2 q; ?) i     alert("重复密码与登陆密码不相同");     
2 u9 S& O" P' z  F& [3 p  P3 j  document.sform1.password.focus();
; e/ f4 A5 C5 D* d2 q! f                                document.sform1.password1.focus();     ! q" @' c$ ]$ Y" [/ Y/ P  k
  return false;1 P4 k" w4 f; H0 h" V
  } , e  Z. O# q! q: Y$ T% H
if (document.sform1.email.value == "")     ' r$ @: m4 _  q/ z+ n  I
  {     ) ~* v; `7 D% M( e
  alert("请输入您的E-MAIL地址");     5 v* i8 l5 R* ^
  document.sform1.email.focus();     " E) D9 a9 q# f/ c$ P$ T$ @
  return false;     * x5 w; T: S( E4 ^/ P! |" \
  }     9 W1 r! u+ Q# e0 K. C' M2 p7 n: H" _# q
      ' M1 j2 S' s& k* }5 \+ o( Y/ W3 f
email=document.sform1.email.value;      
- b8 s. n4 P$ b  o0 E; r" @* L emailerr=0     
" j( H" t& C+ L6 }1 [ for (i=0; i<email.length; i++)     
3 s/ ^% o+ s. E- q/ L$ ~6 t  {     
: r, b, k1 x5 t3 J& ?: P# b. b  if ((email.charAt(i) == "@") & (email.length > 5))     9 U/ |4 R6 q, E0 h' V* @' M
   {     
) G- ^6 m5 T! I# |4 \9 X     emailerr=emailerr+1       \+ m4 J( d$ `0 \
   }     0 O* N- T1 W* {& I# x. B# m
  }     
2 \. \; O/ ?; H2 ^" u$ Y, a2 R  ? if (emailerr != 1)     4 y# @3 y, o1 V) ]; O
  {     
9 I& U+ D7 o5 y  alert("请输入正确的E-MAIL地址");     % G' W5 X4 z4 @0 C# @( h7 j% F
  document.sform1.email.focus();     
& r. H/ [& p: M0 i! |  return false;     
# i4 x+ I1 i; Q" B) B* I: R  }           
+ f7 i  r4 o" t9 v  
- j( _6 S# U2 p0 j/ |2 D; i5 { if (document.sform1.checkask.value=="") ) o+ t" J8 d2 f% ~- ]
  { # ]: ?9 K$ l; m' |
   alert("密码提示问题不能为空");     4 E$ s  v! S* [
   document.sform1.checkask.focus();     4 [- i% B- D( m+ f
   return false;  " f/ M2 @& @; ]/ u- I3 S
  }
! @) o4 [) R# Q0 n. E. N7 @ if (document.sform1.checkans.value=="")
: h! L9 x/ \; j2 }  {
& Q# d+ \' o- b( T3 I   alert("您的密码提示问题答案不能为空"); ; S1 b7 ^7 \/ X; L9 F: G
   document.sform1.checkans.focus();     
& R, v( `  Z$ ^6 r/ ~" o1 e- q   return false;  , e* [9 M1 c& \. i3 }8 h5 U
  }
- w$ z8 H: u: m" x2 H0 |* N return true;     
: i- `* J0 O; r' i7 e( H! F     6 \2 }1 ^6 a+ U2 ?3 j* r
} 0 H6 m6 a) d) u* J3 H$ K( T( t
</script>

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