返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:& K' Q/ Q& t1 S+ T4 h( e7 c8 l
<script language="javascript">     / X" _0 O: z9 v
function IsDigit(cCheck)     7 H/ F& E0 P/ N& b# K/ z
{     ! n3 R# Q; ~2 s. Q" I9 v
return (('0'<=cCheck) && (cCheck<='9'));     9 R6 G9 m9 U2 H- e- v! z; r3 T3 Y0 v
}     
: C' e& H6 J+ l" c& t     # K3 k5 M' s5 ]7 o' Q2 ~
function IsAlpha(cCheck)     ' U4 Q$ S8 Y% }9 z* u$ |% q
{     
( S& J+ {% |. v; h: u/ ~  V return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     9 X4 T6 O/ y$ \5 r9 S
}              
* n4 z8 O% B7 z% Y- ^9 b2 o' p      
5 _5 Z1 ]5 H+ _4 ^+ M& Wfunction IsaNull(cCheck)         
; Q, g) p8 y, z {         
! m" x* [# X, S, K return(cCheck != " ")         0 N$ z6 u9 J' Q; _2 H
}                               6 Q/ T$ X* g- u
      4 H6 [# L3 U+ l$ S8 x
function checkform()     
6 l- J+ Y0 s3 H; S9 N7 {{
6 R$ n$ J- n; v  id = document.sform1.id.value;     1 [( C& _1 |0 Q' u0 C$ D
if (id == "")     0 E7 W3 J& V2 `+ N# f" Y& G1 m
  {     
0 V" j9 O7 Z9 F  alert("请输入注册名");     - o" b4 d4 E& S; d. N
  document.sform1.id.focus();     
; _7 j1 o% d1 @4 m8 v+ [: ~: I  return false;     4 }5 ^9 M% o! {% d8 S
  }     5 h8 i; c& T$ G. T( K
     
  i+ h5 w0 t0 z0 ?) z for (nIndex=0; nIndex<id.length; nIndex++)     
$ D. t1 z: c& |; [. K  {     
( ]' F7 M( U- n- C- m  cCheck = id.charAt(nIndex);     3 R! q  a6 ]  r% @6 h
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     4 e# {  g! G+ m! G
   {     
- j  x6 A4 z& V" Y/ Y   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     4 K7 H0 c# Q/ ~; ]9 P
   document.sform1.id.focus();     ) x5 i$ F3 b: ]: [; A5 X9 c
   return false;     " F8 l. Z! C: b$ U3 g
   }     9 n3 B' m2 p! c
  }
) `9 L' Z3 [. U2 _/ [. i  chineseid = document.sform1.chineseid.value;     7 y' b4 K! A: |$ E* {2 t/ k/ d% L
if (chineseid == "")     
! Z/ r7 [  a+ Z3 c  {     
; W: [& C$ K% t1 }. s' k% t  alert("请输入中文昵称");     + G0 m# R/ v& I, M3 I, @! c( S1 q$ C
  document.sform1.chineseid.focus();     ; x; K  v6 W. e
  return false;     
. J2 x+ R3 ~% A$ e. j  }    ; l+ G6 A- l* s9 c+ `" N( Q6 X
password = document.sform1.password.value;     
0 l- M: Y/ k, k6 N' y. {; I if (password == "")     2 y7 [$ h$ Z! \5 i, V
  {     
6 U3 u4 U9 v8 n" m; E; V9 h4 y  alert("请输入登陆密码");     
; L) `( k! t0 f* `: ~& T$ |3 [  document.sform1.password.focus();     8 U9 c/ r# f7 o; c
  return false;     # ^1 ]( r4 L1 y" ^; K
  }
5 U% d5 J* O- S9 p password1 = document.sform1.password1.value;     
9 z, D0 \9 x6 G' a: ]1 ^; v  ~ if (password>password1)     
& R0 Z! v. H' ~9 R. K0 V( y  {$ G! n9 y) x3 ?: B0 \
     alert("重复密码与登陆密码不相同");     5 H! b3 L# F* i3 z6 W( h
  document.sform1.password.focus();
. s3 M% @( U$ F                                document.sform1.password1.focus();     % w- q$ D9 R2 T. H' z+ A0 v
  return false;7 J# J, {! V; X( M
  }  + ~5 F/ R; [% y  ?! y. C+ c4 s
if (password<password1)     
( X. C( ]! r( G  c. j& [  {+ _) n! K, n" C
     alert("重复密码与登陆密码不相同");     
0 Z* a+ z+ [; {. l) q  L  document.sform1.password.focus(); + j3 Z" {4 A1 k7 G) m1 B: i2 H
                                document.sform1.password1.focus();     : `! I" i) [% E& b
  return false;
& W* A) r6 n4 e  n: S0 j* G3 U  ~  } % h% Q9 w9 m' x( p
if (document.sform1.email.value == "")     
* @. h8 o- s! P  {     % m4 f/ J. ]7 R
  alert("请输入您的E-MAIL地址");     " U8 R+ V! d( T* j  v* W3 i, g0 m
  document.sform1.email.focus();     - m3 H$ G0 s# s* e
  return false;     
: O& @% H2 O# y8 e, a1 {; X  }     
! _7 a- Z: a. D- v      1 s1 I: b1 J/ ?
email=document.sform1.email.value;      & D6 @  P+ }4 I5 z2 [7 Y
emailerr=0     ! }  h5 N! l, f
for (i=0; i<email.length; i++)     
9 }) a- g/ C1 A8 l( W  {     
) m. y- _- U; Y$ w' I  \+ p  if ((email.charAt(i) == "@") & (email.length > 5))     
" W; `" p/ L; T+ z   {     
* H/ {" g. Z7 n3 p/ P( w3 O     emailerr=emailerr+1     3 {* H8 h1 H) i
   }     
( {3 G2 m. a0 T5 u2 [$ f  }     2 Q8 o& u8 }% h
if (emailerr != 1)     
9 [# e# z# o2 q9 G+ ]! B! C  {     ; z# T$ r- y" \, H) t
  alert("请输入正确的E-MAIL地址");     
, Q6 U# n: I- e3 c/ ^  document.sform1.email.focus();     
  A: L' [8 e; F& H  return false;     ' |1 ^% l+ y6 b4 D: d) A7 X- E
  }           7 i. l# w  \, Z
  $ {# S8 l' A0 z  ^/ ?: a+ h5 T$ s
if (document.sform1.checkask.value=="") ' f$ Y" N- P. P
  {
/ g$ A2 B% Z/ V0 m# f9 [$ h   alert("密码提示问题不能为空");     ' _7 L7 z9 r7 \) V& I$ U9 e; e2 U  Z
   document.sform1.checkask.focus();     
) N  C5 i) Q5 K) \0 Q   return false;  + d: s! E6 I/ \3 V
  }
- r9 c7 b2 B4 P/ R if (document.sform1.checkans.value=="")
# `9 S# i* s- q7 q6 G0 Q+ h% n/ R  {
) ]' m/ H. d: O6 d   alert("您的密码提示问题答案不能为空"); 2 d0 G$ Z0 N' r' B" F- x
   document.sform1.checkans.focus();     
) |. J' H: z3 V; [2 V8 S9 w   return false;  
8 [' X: Z7 x( D! \  }
0 W5 T' g& J6 v; E/ @7 l6 b, {  V) J return true;     9 G+ t. `; U2 y$ E. A3 I% |
     
3 r4 ?0 \7 e7 V& s: I7 U}
$ Q7 Q, ~, {2 l' S* @  W2 X' E</script>

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