返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
; T! ]+ _( T) m<script language="javascript">     
7 u" E8 C; t' J& U3 b# M1 `function IsDigit(cCheck)     
7 d/ h0 W; N: v, M) |7 z {     
" t% U& }  k* {$ P; k- _; I return (('0'<=cCheck) && (cCheck<='9'));     
, o& i2 ^' o! r" J4 u. U& M0 a" H }     
7 R3 x( V" N- u  J2 u     
' K& ~2 C: G( Bfunction IsAlpha(cCheck)     " d: B# T  X8 `9 p; I) D; B
{     
4 O* U- a) L# r  c4 G return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
! m2 G9 i' u1 e }              
1 ]+ r3 @2 d; }5 [% B      
; t: |6 X' j, P  C! y- ?function IsaNull(cCheck)         
- \( I8 q4 z3 B7 T, o) {: ] {         
1 K/ v/ v$ H& r9 V" b return(cCheck != " ")         8 W  ]9 }/ O7 o- \! R4 N
}                               " G. h1 w' z. h5 e2 f+ F. n
      
) n, J8 U; v4 T2 e" _function checkform()     2 i9 h3 }* f) w. F/ N  g
{ 7 G; {) f8 Y7 f
  id = document.sform1.id.value;     2 W: y6 C1 P& b1 V& `2 A/ v+ E
if (id == "")     ' U. ~2 Z0 W7 r: X
  {     ) z% a1 c2 G' p4 j$ }
  alert("请输入注册名");     ! r  |9 l+ X/ A9 o+ s+ T% G$ ~  {, B
  document.sform1.id.focus();     
. H/ b5 |4 q) [" ~% |( |/ t  return false;     
+ j5 A6 {3 n- |; q  }     2 f/ W3 t( s$ _$ J4 s
     
/ o9 N  h5 K0 N for (nIndex=0; nIndex<id.length; nIndex++)     ; [3 {: c6 q4 h* n
  {     4 m+ A3 p+ k! b  }& f5 E$ F7 j
  cCheck = id.charAt(nIndex);     1 a' P4 Z: H! X/ s5 V/ h. Z! z3 N
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     1 |& T/ I, f- i0 a
   {       C0 g$ ^" k" _6 ]* ?
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
! m$ M5 k$ s) a( g   document.sform1.id.focus();     $ s4 }1 M4 s# L( L& m' c. k
   return false;     
4 [# x. ~0 i( i" _6 }6 z  k: h   }     $ r1 H# c. Y6 I' B, Q; `
  } ( W0 o" N; ?% W  J7 g
  chineseid = document.sform1.chineseid.value;     ) S: U' P1 z- i3 w: G9 ]' C  ^! u: S
if (chineseid == "")       a5 R4 q8 T3 p4 W: q# S9 i
  {     # V* _4 {, l/ |! C' ~
  alert("请输入中文昵称");     
* u4 S8 N  i/ B# |% B% C( C, s  document.sform1.chineseid.focus();     ( B+ m5 [2 p+ j
  return false;     
1 s6 @1 {* Q- i" e  @% {/ |  }    5 T/ s  g7 v6 i8 a& X! D4 f; k
password = document.sform1.password.value;     
1 ?! ?$ B0 @9 N7 a8 ` if (password == "")     # b- _% ^% x, _' G* p
  {     " G2 O" ?+ K) j: Q
  alert("请输入登陆密码");     
2 \' }6 z6 H4 a. q* |4 O  document.sform1.password.focus();     
0 |- ^. D* @/ |$ ^$ [1 P9 `  return false;     
# B. X' e0 G5 v+ ^  } , N+ g' Z/ l) @) I0 o" @) N
password1 = document.sform1.password1.value;     ( Q9 j. z4 W' I5 R4 B4 K
if (password>password1)     
5 ]0 K, R# O7 @3 b- U  T5 I' ]  {
8 e+ r* a8 O& J2 }7 c$ b     alert("重复密码与登陆密码不相同");     
0 s. ?1 R) p: M+ o1 r/ `  document.sform1.password.focus(); 8 S5 N; g2 N) a9 w) v
                                document.sform1.password1.focus();     . Y' B% F% F  d& B
  return false;& d8 w8 w: q) Y6 B( m1 l7 j
  }  
, n$ B: b  Z% H$ d3 @, Pif (password<password1)     
% o" r$ z7 g) ^+ G! a  {9 q& g4 h7 i1 q' _! e9 y8 F* p3 f2 {, @
     alert("重复密码与登陆密码不相同");     
: g, o; j2 E7 N3 F! u  document.sform1.password.focus(); " X8 a- Y/ S0 ?) @" A6 w
                                document.sform1.password1.focus();     
3 d" W' \4 h6 k5 Y5 C# h  return false;
; S; s" T8 I' Q$ a2 ?3 [  U5 `! `  } 8 t$ }. P. y% w" q* J% O( s0 p
if (document.sform1.email.value == "")     
+ M, N  A' ~% O+ t  {     
9 D( A. B2 r) ?2 l3 ]8 ?  alert("请输入您的E-MAIL地址");     ' c' G* m' r0 p4 p. K
  document.sform1.email.focus();     
. X  y+ i3 G4 L/ W5 C  return false;     
& s; n, j# ?# l  }     - q/ t  @- T/ T7 \& J0 f1 v, |
      
' O( R$ V% i7 Q0 Z/ m. B3 n& S email=document.sform1.email.value;      1 y: z" i7 U# ^  {8 \% q! x. M
emailerr=0     
" ]0 L$ i3 R. ?. N  d. N for (i=0; i<email.length; i++)     
6 r2 R0 q: @/ n; O+ l0 @; \- B, x) \$ R  N( }  {     
5 w* t6 L% u! S6 _: n  if ((email.charAt(i) == "@") & (email.length > 5))     , J) }% O5 W1 y% |8 x0 A
   {     / e; }% Z0 n4 O8 n
     emailerr=emailerr+1     
2 `" g& s+ }' m9 z   }     
* P  X4 O: q, n- H$ y  }     5 Z2 E9 e% |& X! s/ f+ \6 S
if (emailerr != 1)     & M3 {% X5 J) V$ `" @% }5 l
  {     
& T+ A* H% L$ F  alert("请输入正确的E-MAIL地址");     
+ v/ ?# L6 E* ^  document.sform1.email.focus();     ; ?& U2 c- U1 q% E. f
  return false;     
8 Z7 c! Q% V6 I6 e3 i  }           1 A. r' p/ y1 k3 P/ k4 j, b2 N
  ( B! I6 x" @) R. B& s
if (document.sform1.checkask.value=="") , _- K+ r. v6 X& V5 E2 _
  {   _) i3 x8 S# F: V( W' D. a! H
   alert("密码提示问题不能为空");     
! b3 e( o* }, R7 N$ i; `; Q1 r   document.sform1.checkask.focus();     
8 P+ e% k6 _9 V9 `) W/ G( T% `   return false;  
5 x" b8 Y' v* R4 K1 k  } : ]- H7 I% V0 I! `5 t/ h
if (document.sform1.checkans.value=="")
" M! f% l6 l* R" I  {
( W. |$ G1 a0 |   alert("您的密码提示问题答案不能为空");
; h7 E' x, w" s# F/ Q   document.sform1.checkans.focus();     ( [. j( x$ p. X* u
   return false;  ! ^. n" T+ q1 u$ P
  }
5 y% m( h$ K% m+ r- g: _ return true;     $ ]. _, R4 e* Z
     " @6 \! X1 P9 s6 g9 t- j" A
}
& h8 Z& f) s  Q$ i6 F/ b1 {; z</script>

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