返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
9 j. z8 M, r  b8 M8 u<script language="javascript">     
- p7 N7 ~% A7 ?% Ofunction IsDigit(cCheck)     
7 Z) t- I4 w0 A {     
( C; G4 S4 |0 r: z7 Q0 Q0 ^6 U return (('0'<=cCheck) && (cCheck<='9'));     
( J6 s3 h/ ]9 D# k) ^9 U }     9 u) E  F6 i" x) g
     
; w; B1 t/ f: j# D4 Wfunction IsAlpha(cCheck)     
* Q8 L, Y/ `3 i0 T9 _) S: G {     $ f0 T, A4 Q& h0 C
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
+ M& _5 P& S& T1 i+ n/ z4 W; [ }              , C, D, ]% j$ t) Z$ O  k% y9 P
      
! Z' }1 n' m  C6 v& Dfunction IsaNull(cCheck)         
/ E: K4 a% V0 q6 `, h7 Q {         
7 S% }+ B# P7 z0 d return(cCheck != " ")         , W8 A0 s, i- E8 k
}                               9 @' o9 P. d2 j- E6 [
      4 x5 `5 _* V3 y
function checkform()     
' @8 b. o3 k6 g: e% o{
  I# I# x: W! K1 D0 d4 g  id = document.sform1.id.value;     
5 P- @" U7 n6 q3 h if (id == "")     
. X+ Y# O6 a- R; S) U$ P7 T0 p  {     
4 B/ d+ e) ~2 ^$ Z! R. F  alert("请输入注册名");     ( U/ o2 n% H# F; k7 H, ~$ {
  document.sform1.id.focus();     2 n2 L& p( y& D0 o6 ?$ P# t! t
  return false;     
* f" f+ g5 Z1 K+ T  }     
' _9 x' F  V  d1 i, D6 e" S8 R1 r     " `8 E$ F- ~1 d3 J
for (nIndex=0; nIndex<id.length; nIndex++)     ! G# I: l9 `% w. L9 q
  {     5 k/ h+ y& _& o: ^" r( s
  cCheck = id.charAt(nIndex);     
3 c$ ~0 Y' R& h) u  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     8 Y# \" s% x; l5 x# J
   {     ) P; S$ I# w' j/ w' b
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
; \3 ?+ W  F  f; t0 z% L; K   document.sform1.id.focus();     ; ?, ~$ n0 B6 ]9 p
   return false;     # O  N& v! O2 L5 w, @) E
   }     
( q. t; k; [+ R  }
. \  B8 \* Z* X* d) c, z6 ]  chineseid = document.sform1.chineseid.value;       e- P1 I  V2 g4 G5 u
if (chineseid == "")     0 ]* ~8 T! N* g6 f, v1 u/ J
  {     
) Z) {$ B; U$ L! Q  alert("请输入中文昵称");     
* z8 ?$ G$ _2 o0 {- G: ~  p  document.sform1.chineseid.focus();     1 M1 r4 g7 p3 f) K! n. O
  return false;     
# w3 I3 b, v! X! Z5 I, I- U, E  }    . A) D# s! S' a3 D" q  R
password = document.sform1.password.value;     
! H; C( U) T7 Y  x" k: {, F if (password == "")     
% D6 S3 b+ k# c# p( f8 @  {     * v) r7 E9 t' {3 `
  alert("请输入登陆密码");     
* M: m3 N1 s  x# e5 V9 G' _, f5 x  document.sform1.password.focus();     
. T# w5 ~8 ]/ Z/ y/ t$ E  return false;     
, L. ]; l4 S5 }( J, c  }
9 @5 U. D- R4 C+ q) L9 Y password1 = document.sform1.password1.value;     
$ h% f4 }( f5 E% I; j: P7 ] if (password>password1)     
: M! X- p' x, Q  {0 I1 G! x' o2 [4 T( Z! J
     alert("重复密码与登陆密码不相同");     , u: V0 G  A1 N5 L
  document.sform1.password.focus(); 1 N/ y9 d0 ?7 X0 l2 q+ [* a
                                document.sform1.password1.focus();     - M: S/ [" G1 D
  return false;6 {5 ]0 W! U) i: m7 z8 d: \
  }  * q( H' T' Y- |! f
if (password<password1)     # `; D4 J1 S0 B8 X% c& f* i% v* S  p6 Z
  {& E$ s' G" D% ~
     alert("重复密码与登陆密码不相同");     8 C8 K& d& l. g- E- _
  document.sform1.password.focus();
. C$ V& L- }. o: p) A                                document.sform1.password1.focus();     % o) x: V6 q: @: @5 A& `
  return false;. N0 n" p* \! }* N8 E# w- s+ o' }
  }
2 V* Y0 }5 v+ T( Z$ l if (document.sform1.email.value == "")     , h- O" Z) a3 ^1 A
  {     
* M1 W" C+ K6 u" F8 j  alert("请输入您的E-MAIL地址");     * m% T+ j7 X5 {0 F3 _
  document.sform1.email.focus();     
& H! Y( l' G, m# \( H, T- E! F  return false;     
9 \* b, Q3 i8 G  ^  }     
4 ~% G( q4 ^  {8 B1 p! X9 U0 W5 Q      
" R, Y; H' k4 L# r# r email=document.sform1.email.value;        F* D+ ^2 y" w
emailerr=0     
' v& e+ l, a5 F for (i=0; i<email.length; i++)     $ [& L- p& A. |1 e
  {     
- B. y0 R% G; j4 u+ ?# s3 G- l. Q3 s  if ((email.charAt(i) == "@") & (email.length > 5))     1 X) ]: u+ D9 [7 j. s
   {     2 ^' a% e* A5 H/ Z) q4 O1 f  z
     emailerr=emailerr+1     
1 V. V9 p# f4 m   }     5 d1 o# d1 u& z
  }     
; T* |8 w, L) k: @2 Z2 | if (emailerr != 1)     8 H. [$ O8 P. o1 U. c' }
  {     % S, V4 |6 g' y2 h! i
  alert("请输入正确的E-MAIL地址");     
' j# [: \8 m6 e) S  Y* h8 `  document.sform1.email.focus();     0 I) z+ v; T/ F- z8 c3 {
  return false;     , A+ M# s, h  ?( G
  }           
) h* a$ t( w6 B2 x" N. r% ~$ m  / m( P# M3 n" M2 b  D
if (document.sform1.checkask.value=="")
) O8 E- P0 f$ Q8 i  { ! D* [$ Y/ J- b
   alert("密码提示问题不能为空");     & W$ B# r: F; U' `
   document.sform1.checkask.focus();     - O1 c3 k  L! K/ ^+ S* |. `( n" C
   return false;  0 B3 |0 i. u5 D  A, x- K- J3 A7 C, L
  }
. k4 x" i9 Z( N3 s5 n1 m5 d; M' l if (document.sform1.checkans.value=="") . @0 B) c% L7 Q: |% o- N
  { & W/ K+ a! r8 i4 s  V8 L, g
   alert("您的密码提示问题答案不能为空");
* c% `3 {5 N, {; j: b   document.sform1.checkans.focus();     
) B' E6 n4 M2 v, d8 R4 ^; D/ j   return false;  
5 |8 D  i" e2 H: m7 _' [  }
$ O# A# @& g7 c3 { return true;     
  k+ W9 L: l5 l; K& }* i     
; }! B' \) X0 Y; W4 A3 ^}
# ^( Y' U; M; s- J! H</script>

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