返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
( ]  a2 Z: w- i8 U<script language="javascript">     
/ h! ~0 u! H5 Y& Q# Wfunction IsDigit(cCheck)     - x, E; R, }; F% j1 d! I% G4 N+ ]
{     
0 w& X6 c: s6 M" n! C: u return (('0'<=cCheck) && (cCheck<='9'));     % }; k0 t, h9 m) S/ S3 \; i) }
}     
; v& G# v/ u7 @: ^. u     
, A# N+ y1 B4 h( J7 i8 vfunction IsAlpha(cCheck)     2 L: v! R$ j1 O# i& [
{     1 U2 Q! r0 t' C9 D
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
* Y' D$ ^# g* |, u: M+ d+ j' r }              
  \1 U' W; c+ o      
1 x9 o3 @' ~# qfunction IsaNull(cCheck)         
7 `, y! \6 P" q' c& c2 B) m5 n  J  G* F {         
( y/ l  D1 i. m4 Y6 O$ z4 |; _+ n2 L return(cCheck != " ")         $ t& H. A5 g5 Z1 E
}                              
* W% y5 {5 I/ D! U# {      % b+ r! u3 M* w; X+ E4 v  w
function checkform()     3 a3 P  |7 k. q( d3 X( v! ~
{
) T6 ]- @% V& s$ r; I  id = document.sform1.id.value;     
3 C3 \2 `0 c6 K% \5 o if (id == "")     
+ O3 v5 i, c1 T2 c4 m5 a5 @  {     0 M! D, o  g, ^, i, U
  alert("请输入注册名");     
7 X; `* i, T4 c* N: `3 w) A& @) Q  document.sform1.id.focus();     & u1 s! o) S# c
  return false;     
& k6 `- T1 I0 P( j$ [  }     9 f, y2 L* g4 y. d$ X+ t% R- U: P
     * b1 B& v3 c% U0 \  V# F
for (nIndex=0; nIndex<id.length; nIndex++)     $ s" j8 ]! [, W* A# g
  {     1 Y% _' z; z9 `  [* t7 }8 T
  cCheck = id.charAt(nIndex);     4 M' x: p% o2 m. ^9 e" R3 H) a
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
) Z4 R# c! Z2 k3 J3 B   {     * n; I( L  z( G
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ; P: r! W  N2 {2 T# {) q: I+ o2 f; k8 P
   document.sform1.id.focus();     
8 i% W5 z3 P) h* Y% P" F6 b$ ~5 x   return false;     
- _, n$ \2 t) T2 c7 A- N! _   }     
) m5 N" d: C% j; S  } / {! j; Y7 _( E  o9 ?' G- F
  chineseid = document.sform1.chineseid.value;     3 r: A1 B  s1 {( {
if (chineseid == "")     % G2 a! f1 k+ \& c# ^; @0 p
  {     4 ?" D) L4 Y9 y) e& H* Z. Q! T
  alert("请输入中文昵称");     - l+ z' f9 ]0 _6 v7 ]$ W& x
  document.sform1.chineseid.focus();     
  K2 A: u6 L4 o; F. T0 ?  return false;     
. m# n, f2 I7 m1 c) j! @* q2 {7 Z  }    : `# c  D  g6 G/ i- b
password = document.sform1.password.value;     7 Y/ F0 B7 L- C1 c
if (password == "")     
% e2 ^) x/ L# u  {     * G/ o, N* B5 y0 E% P$ j
  alert("请输入登陆密码");     
5 }7 ~- w! K; M5 y  document.sform1.password.focus();     
8 k! `& E7 }8 j% k  return false;     4 H3 x4 i2 b$ K6 Q
  } ( Z7 X0 z1 s, Q0 T: t
password1 = document.sform1.password1.value;     / v& }0 J; Q1 y+ `
if (password>password1)     - m* {0 h- c; B$ ]( v& `- _$ G
  {2 d9 s" m- M; `* a. p% Y
     alert("重复密码与登陆密码不相同");     
! U$ }5 s+ [! X! C8 i3 m  document.sform1.password.focus(); + V0 O" h* c! |) V" E1 y
                                document.sform1.password1.focus();     : ^( k# j7 ~3 p) ~$ g/ F
  return false;+ B4 {9 b& C! P6 ^, B
  }  1 V, b8 S0 e4 j6 M
if (password<password1)     % s# N% v& @8 [3 }( f5 h
  {
, y5 ]) X6 _- [! S     alert("重复密码与登陆密码不相同");     
8 e+ s0 C) @" Z8 N  document.sform1.password.focus(); 8 O' k# ?+ x6 G9 D; k9 O6 r
                                document.sform1.password1.focus();     - I) ?! E6 I8 F
  return false;
6 |' v9 K$ v; L0 i7 |# V2 J  }
) H5 L2 c% y* w0 f if (document.sform1.email.value == "")     0 G( X! u2 f8 ^, ?
  {     % k6 W+ d5 F" t  N
  alert("请输入您的E-MAIL地址");     
( O# ?+ Z- c$ I5 F+ {, }3 Q1 M, X  document.sform1.email.focus();     0 D0 _7 Y' b# `1 T  v; X. Q
  return false;     
( \" ^. O# \4 P  }     0 l' v  c1 u, b( K
      ! K# M% I! x- E% z* F  v
email=document.sform1.email.value;      5 D# O% A2 O, W3 E- X& K
emailerr=0     
, ?7 w6 j+ x' n2 B$ m for (i=0; i<email.length; i++)     
, w+ m, q, l# X' k  {     ' l/ Q# P+ E% U* c
  if ((email.charAt(i) == "@") & (email.length > 5))     
& k/ L/ v. t2 ]3 g) Y( h   {     . V. M) p9 D5 E1 R. l2 e$ C0 {
     emailerr=emailerr+1     
2 F, T$ S  Q3 T3 R# P. Q  W3 p   }     - w, q' Y2 I3 l) w$ I4 l: K
  }     , H8 p! [8 `2 Z# N
if (emailerr != 1)     
  S( {% F1 l" p; q, J  {     
& X, L% r* K/ ?" O0 ~+ h  alert("请输入正确的E-MAIL地址");     ' ?( x% p" T5 q3 _9 e/ S9 L
  document.sform1.email.focus();     
+ B. |6 Q, }6 r$ m, E# a3 E  return false;     
/ g! w# I# m4 [3 R  n  }           ) u+ a( h8 ~+ A; u* s
  + \' R/ F' O5 Y7 u5 [- ]
if (document.sform1.checkask.value=="") 9 L0 O: S9 t: q2 E  C7 s
  {
* x" s% s2 H1 V' v% s7 {5 X0 B   alert("密码提示问题不能为空");     
/ C  v( \- `0 E   document.sform1.checkask.focus();     
0 H3 C! U$ I5 L) \" c; d   return false;  
% g. l. i9 z. O7 g$ o' X6 [  }
( s0 ]1 H7 O5 i$ x; v$ B; b if (document.sform1.checkans.value=="") " p3 A/ V5 [& Y" w  c( Z' H) m
  {
4 |4 q2 ?6 [- g% p' H   alert("您的密码提示问题答案不能为空");
% _9 |0 A0 [9 f; R/ i   document.sform1.checkans.focus();       I7 a1 X5 |. W- p
   return false;  7 D) Z/ B3 d. e
  }
' K0 l: l8 ~/ O0 {, h: j return true;     # Z. ?- l" x) [" e' k
     ! ]8 l; S: B: d. |1 v
}
, G: l/ h! f6 q</script>

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