获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:2 i: W2 V5 V# d
<script language="javascript">     
) c7 d6 o9 c1 e1 Qfunction IsDigit(cCheck)     
. V0 r5 M+ \# G' w3 A/ _8 {  Y" }& t {     
6 [9 L/ l( ?! [8 n  C return (('0'<=cCheck) && (cCheck<='9'));     
9 F( }2 O& F! b) J }     5 h. v$ g# o( m# N$ ?/ e4 o
     
" r& j2 ]$ x- j) A9 Rfunction IsAlpha(cCheck)     . ~" R- S8 p1 W. y
{     
9 f0 J+ B3 L$ K2 F& |+ [# f. i" O- f% ] return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
5 r& P- M4 n/ w7 y }              
  s9 A5 ^, Z2 r      4 R8 T6 I' W* `* Y
function IsaNull(cCheck)          2 e) L. S- O. u$ `
{          * k2 p( k$ t5 R- \- m7 b
return(cCheck != " ")         
6 _3 {" s) ?; B7 \9 {9 V8 ^4 T) _( e) ? }                              
6 a$ _5 w$ T4 _' U; n; t: t, h      % Z" |2 `# s' m' {+ A( s5 U
function checkform()     
. n7 V8 i7 t( V9 A0 n! H: l, Q{ + v9 u; F, U$ j: x" q
  id = document.sform1.id.value;     . J3 J4 h  r& J: \
if (id == "")     
' I# f& V- P( N  {     ) s6 C  H3 u0 V( S7 l0 k# y$ a
  alert("请输入注册名");     
, L  G; {, |: [3 p1 J1 o+ Z" t  document.sform1.id.focus();     5 M. @4 ]  ~/ w& {* \5 L
  return false;     ! x: D0 P8 |& L; x
  }     
; h# |" c0 E4 T* V7 E4 O1 g# S       \+ E' `1 N$ x, ~* L
for (nIndex=0; nIndex<id.length; nIndex++)     $ m4 ?$ r# U0 P( h! `' x  W- U* {$ \
  {     
% I' W6 v2 F/ [$ a0 [  cCheck = id.charAt(nIndex);     
7 V  y/ O  u7 n& z" g5 q2 M  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     : x* F2 i% o: J0 m+ a5 ^5 X7 E' I
   {     - A* \$ o/ ^: ~$ [4 `
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
, B) i& U4 s5 k: Y8 @( B3 H8 {   document.sform1.id.focus();     ( r. }( J/ k, @6 e+ k
   return false;     
( K( h4 k$ @9 |: J2 ]" T% Z   }     " @8 l4 z$ X, u+ [8 R
  }
6 |4 \9 D( u5 S" L9 \2 L  chineseid = document.sform1.chineseid.value;     
: x! M3 N* b0 @9 x/ [! v9 L if (chineseid == "")       g* r) v* e5 {2 M$ R
  {     ; {) H8 p4 D, ^) {. G1 N$ C6 |
  alert("请输入中文昵称");     
5 P3 M" ~: F, \' F5 J6 o, f  document.sform1.chineseid.focus();     - }4 @( l. v3 Y9 t! C) ?/ ~
  return false;     
8 c% K' ~, C$ a2 r) l& M  D  }   
# I5 Z- ]$ B3 c* C password = document.sform1.password.value;     
" }8 q+ D4 g: I& F$ ` if (password == "")     
/ ]: Y% Q2 N9 B  {     ! Y, Y8 L: q3 X' g
  alert("请输入登陆密码");     
+ a& s( ~( H4 f& x  document.sform1.password.focus();     - J: Q/ B- }: q+ J: Z8 t7 v
  return false;     $ u. T) [% G( c2 X
  }
7 H/ J. F1 E$ u7 m7 O9 l6 s password1 = document.sform1.password1.value;     4 X" U/ C# J: L' z5 N9 B
if (password>password1)     4 {8 c1 z& O% I
  {
, }0 r7 k4 C9 g4 ?# B. E2 `     alert("重复密码与登陆密码不相同");     
4 Q0 T' Q$ T  d, G  document.sform1.password.focus(); , C; ?4 N3 Z+ @, _. Y6 g% b; l
                                document.sform1.password1.focus();     ) w9 e9 Z3 }1 E- M7 b$ a
  return false;
+ ^, j! B6 K$ f2 W8 U  }  
5 I7 ]6 c& @  q9 A) b" m  j0 vif (password<password1)     
+ R" I. j/ ~5 S: Y: F  {
% J% }% D) E3 N  O+ }& f# Q" w     alert("重复密码与登陆密码不相同");     & b; B# f: b0 O9 V9 m
  document.sform1.password.focus();
  D% H1 G$ r3 d( O, \1 V" c" y/ F) M                                document.sform1.password1.focus();     ( G0 x# t% a8 {5 Q0 ^6 q
  return false;- }! G4 E$ c# m, M; v( T
  } ' F+ M( t- |; C4 b. W7 Z6 j
if (document.sform1.email.value == "")     
. d5 k- L4 B1 Q. y* T  {     
% U7 }, W$ R" I  alert("请输入您的E-MAIL地址");       k2 H) M) q4 N. a
  document.sform1.email.focus();     7 g1 j- A& L4 A$ c5 U, Z  s
  return false;     1 |. A* S2 ~3 ?7 E9 H
  }     . k5 n3 U) K& R% {1 H2 \
      ) C; d8 n  J2 j. @; ~2 Q' A
email=document.sform1.email.value;      2 F' y% x- r2 Y+ N6 T
emailerr=0     
) P6 P4 K* M* J; K# }/ f8 |. _. [% x for (i=0; i<email.length; i++)     
( r( ?. v6 W# g  {     
; B% h- q5 ~+ u, s4 b3 @  if ((email.charAt(i) == "@") & (email.length > 5))     ' G! m. s: V, y6 @
   {     0 K1 X, U1 h9 C- Q+ r: v
     emailerr=emailerr+1     
6 s# r5 X. g9 t. ]7 [3 U' [0 x   }     $ U& ~5 S5 }+ T* e
  }     : e8 a% ~5 z( x: {5 e+ g9 I1 g
if (emailerr != 1)     
/ v+ s2 I9 e% I( Y  {     
' Y# m, d! P; P/ i% s' t% G  alert("请输入正确的E-MAIL地址");     
* S( \: l& E$ I- v  document.sform1.email.focus();     
4 b$ r  r( n! ^4 ~2 F  return false;     
1 x* K5 q1 X  s1 n8 S  }           
2 {6 k' _  k% V( z' y  & N3 r! r( Z. f  ?4 n! S0 o
if (document.sform1.checkask.value=="") $ v+ e9 h. n* D" s
  { & b) }) [4 `4 O: O
   alert("密码提示问题不能为空");     
* K% r. b4 P/ Q8 z" a* z+ B   document.sform1.checkask.focus();     % k1 l" |1 W% n$ p, H0 E5 E8 ~
   return false;  
; V4 C$ x" [8 I; h3 Y  }
( B6 h* W5 n2 b( f  Y/ G if (document.sform1.checkans.value=="") 0 v0 l1 P9 @0 a. O3 R
  { - {/ Q: R3 @. E- ^2 Y
   alert("您的密码提示问题答案不能为空");
- H& {2 P* s& s/ g4 v  U' V* D" B   document.sform1.checkans.focus();     6 k: W; q2 a  p( c. R5 D
   return false;  ; z* Q7 j; y7 X! h2 N# A  O
  }
! x/ \: |! H- M4 m return true;     9 [% z, ?) Q, ]( J& m3 t
     6 T  M* s# X! q2 V& i
} + G7 T& J# H2 m# _! c& [; i
</script>

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