返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
0 \. l+ E; y, h4 [5 z<script language="javascript">     
" s( a  c# T  Z6 X2 x+ t* {function IsDigit(cCheck)     , h0 }6 g$ c2 f, f
{     
" D$ _# l* \7 M return (('0'<=cCheck) && (cCheck<='9'));     * K5 `" |4 p2 T: ~* |6 W
}     , w8 k  T  e2 y, t! o# }
     
! m/ C5 s& c+ K8 x* Hfunction IsAlpha(cCheck)     1 E/ T  }2 w; k9 r# H; \. O
{     + P$ o6 Q9 M% t* k, Q
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     0 ^! L" q7 f0 B' q: y% E, a
}              8 ?1 w/ O$ _+ X# L& U. A
      
+ e2 r) R0 r: v4 g4 Ofunction IsaNull(cCheck)          . |; t/ U' @/ |6 L$ c! M0 k3 M6 V+ R
{         
- j) Y2 Y( G% d1 d& e return(cCheck != " ")         & O9 [1 P/ n+ i6 O+ x
}                              
5 N9 i# k! ?4 |* P  T      
' W, [  G" H: wfunction checkform()     ( b( _; }+ ~0 h) I& J
{
0 X( {+ U3 c$ s2 @- G$ D  id = document.sform1.id.value;     8 Z3 N1 p" N9 j: @/ z' h& H# `9 w
if (id == "")     9 K, v4 E: }. _  C5 P
  {     
3 s) {2 ?! S. D% G0 H) T1 S  alert("请输入注册名");     
9 i. M+ N, ^; P. U+ I' w  document.sform1.id.focus();     
  E, D& |% C+ V2 r: X9 j8 [$ u  return false;     
' i% r. I" G0 R8 N5 j9 v: n  }     ! u. G6 R: K% `( J2 C
     # Y5 F, k" |) W; B: M6 t: L
for (nIndex=0; nIndex<id.length; nIndex++)     
" q( `) [6 U; f! E( s# V" T6 b  L  {     + V( f4 `5 A( {
  cCheck = id.charAt(nIndex);     
5 H2 [1 g' P' e8 }3 u6 p2 q6 r  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     4 d$ z3 h4 P, `7 d
   {     
; X# X6 C9 ?6 S1 ?8 ^7 Q( G% y/ V   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     4 _( ]* h% X  A1 o' w: ~
   document.sform1.id.focus();     " _( m1 l4 {7 I) n! T3 L
   return false;     
5 H" l& l$ ^! y: a4 U9 d+ D% o/ }   }     0 m5 ?* F. t7 W  J/ N! S
  } - R, i9 O! v" a1 P8 j, M+ O
  chineseid = document.sform1.chineseid.value;     
/ k( S, @& h' s% {8 b/ J' Y if (chineseid == "")     $ U* _/ u# |" d3 W3 P; A. `
  {     0 I& k! [4 s* \5 L" T& Z
  alert("请输入中文昵称");     # X$ P8 d8 b& |6 Q
  document.sform1.chineseid.focus();     , B" ]/ e- R, @# l4 M
  return false;     # Y! j7 ?0 e& c) [$ n, [* m
  }    ! o" i, Q4 J- ?8 Q8 e# }
password = document.sform1.password.value;     % Z' U9 h% s% E  P7 U- M1 p" D
if (password == "")     
" X: U& I' b1 r# g( N% ]  {     6 A5 g5 \6 K2 |5 A, V4 C
  alert("请输入登陆密码");     
) w  D3 G5 O0 L  document.sform1.password.focus();     . G0 `9 S' R+ U
  return false;     
; C8 i# S$ r7 O1 ^7 K  }
9 U! g) D, T2 R8 P. S0 F8 [ password1 = document.sform1.password1.value;     7 W$ e  y# g3 G& {5 G# ]
if (password>password1)     - ^$ j0 G$ j* |/ {6 y  K) q
  {
" E+ a+ ?" I, e* h$ s' S3 F     alert("重复密码与登陆密码不相同");     4 R: p8 `9 C  l, C3 T, `" E
  document.sform1.password.focus();
8 C% N' k# U' n3 R3 D& M- q                                document.sform1.password1.focus();     
' O; U0 r- ]! B4 E- F; f  return false;8 X+ z  N: O/ ?) ~; d
  }  
0 s( Z8 E: o( H, Aif (password<password1)     0 m- G" {, [# o. `4 G
  {! B" U+ ]4 K7 m+ P
     alert("重复密码与登陆密码不相同");     
) ]* K& H+ w# C  document.sform1.password.focus();
) h! _, v7 A! g* j' _" ~                                document.sform1.password1.focus();     
- X/ k) z$ y7 U- L  return false;" V# E5 S; }+ b2 W/ f
  } % o# R: L, z5 r" e/ M* Q- ?
if (document.sform1.email.value == "")     : X) K) @; [& y5 M: J. P
  {     ) q9 {3 y8 c# C& l. X0 B
  alert("请输入您的E-MAIL地址");     
% L6 ]$ I5 p) K: \5 V2 X. F  document.sform1.email.focus();     2 g4 J; r5 c1 M) X. N
  return false;     
1 e1 m* Q3 P# i+ k$ s) I% }0 C  }     " D) C: t" L1 k! g1 ~
      
6 w. u6 a* w9 v9 R3 |7 Y+ W email=document.sform1.email.value;      % V6 ]# D: g% n5 F! x
emailerr=0     + U0 n: _. U! X& |) J4 @
for (i=0; i<email.length; i++)     ( m3 G+ F# V* z6 ]# j% R
  {     
1 G! i2 V0 C- Z, J; Z+ O0 T5 l8 I  if ((email.charAt(i) == "@") & (email.length > 5))     
8 e+ n/ E' J% W. L/ [+ J" t# t& I   {     
8 n5 @! f, f* [  Y) U- X     emailerr=emailerr+1     3 O8 z# O7 h2 a9 [8 D+ M/ E8 e9 J. C0 ^
   }     ' d7 p2 a6 r+ w# V/ s4 ^
  }     " C' R" E& _6 w# x
if (emailerr != 1)     ) V- p. E, z, v
  {     
4 P9 l  k8 @9 {* F7 O  Y: y, `4 o  alert("请输入正确的E-MAIL地址");     
5 g8 @$ ]5 l1 V" o  document.sform1.email.focus();     
6 D# [& u- X/ l/ k( u# P  return false;     
; H% m$ Z/ a$ b- _" N( o  }           
9 U" t1 L; M; J, s$ R% A    U( e" J* k, x. _, h
if (document.sform1.checkask.value=="") # z4 A$ _/ g! F& s% p
  { 9 Q4 G, g$ `, |1 X  \
   alert("密码提示问题不能为空");     
5 `. q, c. t$ x   document.sform1.checkask.focus();     ( H9 }/ o$ [8 s% b: d0 v
   return false;  
% ?: {7 s$ U1 F* q  } " F5 \  Z1 Y( e! e+ k. d
if (document.sform1.checkans.value=="")   K5 S" h7 R( p; ~4 h' U. a
  {
4 y2 B9 d0 e& B; [   alert("您的密码提示问题答案不能为空");
) p( Z+ n7 O) t8 U2 O   document.sform1.checkans.focus();     8 g! @1 Z- P" @  p( [2 G8 ~. p- `
   return false;  
0 t. x" y- K8 f1 m5 I% a  A  b  }& O3 y7 S3 c$ e: v7 c' L  C
return true;     1 f" @- f1 H; }# K, Q% C
     
# g) M( e  n& |2 O5 v5 D}
; F. o& r5 x" y2 M+ P, D</script>

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