返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
" r! f1 e2 D2 a) `7 l<script language="javascript">     
6 _* ]* f* f7 K( z# Mfunction IsDigit(cCheck)     8 O4 p: n( G" N
{     ; `4 l+ ?0 u5 j5 e
return (('0'<=cCheck) && (cCheck<='9'));     , o3 l& D" i; P
}     
: m1 R8 |, X& z( m4 M     
3 D, ?+ y+ r" W- ?: {function IsAlpha(cCheck)     
. A) _9 U- w$ o- k6 x1 g5 Q {     ' M. R9 U: s% m9 E' v/ L
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     $ K5 M. h1 y2 R6 l
}              
9 S" @( M) T* [" ], ]      : a3 f; `. W( s9 Y
function IsaNull(cCheck)          0 |: r- \3 L: w2 H
{            u4 o% }2 q: s9 M* F
return(cCheck != " ")         # M+ }' f/ F. \# }; |& G
}                               7 l4 w' x- |  I. H
      
$ |) a  p% X- p! u7 k5 ?, Jfunction checkform()     : D* {4 G! Y4 d0 l" f0 ~
{ 5 z$ b6 M: a5 L* u, w4 i6 q/ @
  id = document.sform1.id.value;     4 {- W# K, N! p1 Y0 X. p
if (id == "")     % L" z. f- h* ^0 w
  {     
5 i2 |2 Q. U; l$ W7 S* P/ i$ P  alert("请输入注册名");     
9 n3 C- F  {) {1 r2 l  document.sform1.id.focus();     
" E" ^: M- k& {  return false;     
7 J1 d. M- u4 r+ f4 ]% I+ e  }     
/ S, E" b, r2 y) }8 U) J& _  G( p     % j- `3 k; U4 i8 _
for (nIndex=0; nIndex<id.length; nIndex++)     
( K) {& c, j; X8 a5 q9 r  {     
8 B. }. P* V! g: E  cCheck = id.charAt(nIndex);     ; e- V# s- i- a# E
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ( K. W  ], L$ t$ u& h2 M6 t8 d
   {     : o; A+ {3 L/ P
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     8 s% R- s% E+ [1 \6 Z. s+ T
   document.sform1.id.focus();     
4 V, l4 ?) U2 Y+ J, w6 R8 n. y$ Q; A   return false;     
# G( V* }6 \1 G; f( S6 ?* u4 ~/ W   }     
' ]5 \6 y( ]- `) A  }
, c% m; T" k! g( ]& z5 n  chineseid = document.sform1.chineseid.value;     3 T9 C$ e, |9 N/ B6 k: ~: A
if (chineseid == "")     
; F- _, o6 n: \1 l7 h& Z+ y0 g+ z  {     
" u) q, @/ |, l# Q8 U* H  alert("请输入中文昵称");     % A. K* d$ }5 A5 W- K/ w
  document.sform1.chineseid.focus();     9 Y  u2 s8 c/ P# h" S! H2 m, j
  return false;     4 m; J/ O& `' x* h
  }   
1 \$ Y) N6 [' F4 |$ F password = document.sform1.password.value;     
* q% z2 D$ V6 ~0 ~6 _6 |/ [) k; l if (password == "")     
; G  O! {5 Z6 |) K. P+ s6 b5 n  {     
& p' `8 M. \8 M* d3 I" i, H  alert("请输入登陆密码");     
4 ^9 p9 M( M9 h  document.sform1.password.focus();     
5 S. F  L1 r& v  return false;     * k  [4 |* N  }1 z8 _$ G
  } % g3 n$ k' d# }1 N' B% a7 \
password1 = document.sform1.password1.value;     
" t( q% u& v) x( i3 `3 w if (password>password1)     # u& f; D9 M  P! [; Z  A
  {
% k" {' d& S6 Q/ o) J5 S* N     alert("重复密码与登陆密码不相同");     : ~$ O/ X/ F4 o! r
  document.sform1.password.focus();
3 f/ i; W+ `& k* ]  V                                document.sform1.password1.focus();     
" ^: z- y3 D6 a# D  return false;7 o$ }4 d  B. G+ C/ l" d9 L
  }  
1 M0 F3 S, K) b( U; t% V; r$ @* c- lif (password<password1)     
/ E3 m5 z; {9 l& L& h! ^  {% ]6 v+ P6 ?$ o
     alert("重复密码与登陆密码不相同");     
. J  C9 R' ^2 g% F: ?" z  document.sform1.password.focus();
+ W, I) A' F" e$ T( g                                document.sform1.password1.focus();     
( _, F+ @3 p# o4 \0 X7 a  return false;
( H' b0 ^# c1 o" _; s2 r4 U! R  } 9 J' a, C4 l9 b( T) u! f
if (document.sform1.email.value == "")     ) R1 I" _# Q8 c
  {     
( Z4 O. J* b; G  j9 A  alert("请输入您的E-MAIL地址");     % ~6 h% t* m2 k. X. G) R
  document.sform1.email.focus();     - I  h2 r7 U1 B; C
  return false;     
; B" e+ z0 N% @) G) e3 _  }     
( \6 I' ?3 [2 W; N      
$ S2 J7 x6 i$ v1 D1 k email=document.sform1.email.value;      
; L3 t1 r& `1 {: z& a( z$ _- b emailerr=0     ! t3 z! X5 F( D: K
for (i=0; i<email.length; i++)     
- y; W9 U8 u" A  {     $ E8 ^4 u, Q1 J% M/ i' W
  if ((email.charAt(i) == "@") & (email.length > 5))     + x% x& H" X$ u9 a. G
   {     
4 ^) R1 ]  s% \# x3 E     emailerr=emailerr+1     
* y. u: s/ G6 O; T# f   }     
1 \3 x! t1 A8 w  }     
2 E5 p" q0 Q: ?7 ], D* ] if (emailerr != 1)     
5 t% w$ T5 a+ L& _, L  {     / X8 c, y7 z4 p% i
  alert("请输入正确的E-MAIL地址");     
" ?1 P2 Q# ^1 C' B  document.sform1.email.focus();     
. `( M- `# E$ \( D4 e0 n0 m  return false;     : N' B5 L  t+ O! ^& D3 ?
  }           
/ M- b& O& O, x0 j  " Z* D0 S  V( t2 b
if (document.sform1.checkask.value=="") ( r7 T* S3 L3 T$ }; E
  { ) L5 x5 Y  X+ G# R7 B- p" h$ b
   alert("密码提示问题不能为空");     # a$ X# b$ ]3 i+ j
   document.sform1.checkask.focus();     , ?0 `; W& _8 \3 }3 u6 f
   return false;  ; z- l3 d- ~8 _* k
  } # ~& m! E! ]! P6 X# a+ ]! |( r: h
if (document.sform1.checkans.value=="")
' x7 F' X3 z$ e) Z8 `! G  { & G( P* a) X' ~; q; z
   alert("您的密码提示问题答案不能为空");
4 w+ Q3 B7 f) D. x$ h   document.sform1.checkans.focus();     . ?' p/ e4 w& j% m
   return false;  
, J$ h/ M2 E, ^7 e% r  }/ ?7 S1 v7 F* l! P/ F
return true;     
; W( X+ l1 |7 V# @9 k# G0 O' \     
7 Q9 `8 U" O' R- K1 N}
# ~; s& |  w% z! K9 O</script>

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