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

一个注册表单验证的js

这个脚本对你可能有帮助:. u: ]) C- x; r  E! w. v" s5 e
<script language="javascript">     
! k5 g; F7 M# C! u5 s2 d' V' |3 rfunction IsDigit(cCheck)     
" E" j- a6 I  t {     ! x4 N, i+ W: B9 z, n1 l, V5 m1 l- E
return (('0'<=cCheck) && (cCheck<='9'));     * m* @, y/ }8 v# P9 [
}     
; y8 }1 O  d) s" s7 \2 K1 G     " V4 P, r+ ~. }: m9 f
function IsAlpha(cCheck)     
3 ^% Q' }  o& e6 B' G; K1 Z {     ( m3 |  w) N8 c/ K, v6 {- [
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     & c2 W$ g1 R6 V
}              3 R: m. y8 ^% {" s0 H
      ) g* A/ H4 Q- Q6 T* r: k
function IsaNull(cCheck)         
5 d* g6 R$ q4 _. x {         
1 C; A- c* F( J; M2 H0 j return(cCheck != " ")         ' ]: i1 `% M: R" J$ M; S
}                              
- u* [, U3 B( H3 p7 }4 O: B      
# I0 v/ Q8 R6 c; D, [8 Y3 Sfunction checkform()     & M9 F% p( r0 J# n& z
{ / V! U2 k  \. a' }
  id = document.sform1.id.value;     
% W0 v9 j$ B7 h! W if (id == "")     
% U" p. N8 V1 t. u5 ~$ O1 \5 Q  {     3 |9 s/ t& l0 p
  alert("请输入注册名");     0 B3 G; ~: k: j2 K. B6 ~) d
  document.sform1.id.focus();     
4 a5 M( o$ d; L/ f4 u( ?) Y  return false;     
0 r# ~0 t7 ~" p% {# `( X& q  }     
. V/ w9 N4 v* N3 `# e     - r0 L! R( a/ j
for (nIndex=0; nIndex<id.length; nIndex++)     
8 J/ W3 B! X7 V. H  {     
3 b' M5 [% i; B; Z# G+ C5 {  cCheck = id.charAt(nIndex);     
% r2 ]. [7 G+ \) C0 |3 {' U  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     4 o- _3 V( z# i# r
   {     ' i# C, J4 Z" w
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     / `$ l8 S7 O; C) F4 V7 ~' w
   document.sform1.id.focus();     ! [2 U1 w  _1 x8 j, `: m
   return false;     & i8 `) F, k9 J% d& ~
   }     # }# H3 f5 L! }( a& `" F
  } - r4 Q2 k# x% c3 p' ^- i
  chineseid = document.sform1.chineseid.value;     
" c7 X. ?+ O  b9 f1 q7 {( X7 R if (chineseid == "")     
4 m% e; v0 O# w8 m$ a: d9 K' a  G  {     
4 @8 `+ M* H+ ?  i1 R  alert("请输入中文昵称");     : L3 u* E0 e- H+ R& ]
  document.sform1.chineseid.focus();     # p2 l5 U& Y" ?0 L) f5 l
  return false;     
3 K4 `' p6 x& T: l# e4 |  }    5 ?% y* S- F4 s5 y7 m) K+ e& s
password = document.sform1.password.value;     $ Y! ?+ z: b# l7 x
if (password == "")     
2 W6 K; m, N4 P% K5 N+ Q- f  {     1 J1 ~0 R  l$ }0 ~! Q+ g
  alert("请输入登陆密码");     
+ W7 j/ H$ R9 M' }8 \: n( w$ S  document.sform1.password.focus();     
5 ~3 N# b8 \. s) s  return false;     
, u4 h8 a; e& g" M( y4 j/ a; f  } ; c8 L! F$ A+ w, n+ H+ m  K; Z7 X
password1 = document.sform1.password1.value;     & T, }7 B+ m' k: ]3 @) K' `: u: e
if (password>password1)     
/ [/ Y; {1 c0 w  {
3 ?8 _3 P& q7 a     alert("重复密码与登陆密码不相同");     , ?! T. V5 d/ I
  document.sform1.password.focus();
4 n0 N) r; T! P( |* ~                                document.sform1.password1.focus();     . L! I/ C  Y& S7 Y! n
  return false;
% N5 ?7 Z; Z5 N& g  }  5 o. h" `) p$ p) d2 Y6 ?: |) g
if (password<password1)     ) E$ n2 @' O1 @  b- m4 n' s
  {
- v3 }+ S% v7 J     alert("重复密码与登陆密码不相同");     
3 I; N4 M: h: n# Q  document.sform1.password.focus();
5 e6 l4 T9 Z4 W7 N5 K% [  F7 a$ @( e                                document.sform1.password1.focus();     8 p8 s6 [; w- ]8 k6 W
  return false;
$ e: \# _/ e9 d/ |9 A& Y. b) E% y% t  } 7 F* L# p* q5 r
if (document.sform1.email.value == "")     
# L6 o  ?& s4 x5 S8 @, b, [  {     
* G/ v! o$ U4 V( q( L) L( [4 y$ q9 h  alert("请输入您的E-MAIL地址");     / y0 _: j& G/ t" b2 L
  document.sform1.email.focus();     - I: `) Q. Y( H( ]: y
  return false;     
4 t7 w7 z& j' Y& x+ X) x: p& e  }     ! \) |+ j9 L2 N+ @
      ( V+ b; p# ]5 B4 U$ P/ D2 f4 B. H
email=document.sform1.email.value;      
( V( G  v9 `( T8 ] emailerr=0     1 |$ c$ K' `+ P5 v5 @+ z
for (i=0; i<email.length; i++)     
: i0 ?4 b" H3 u* E$ v  {     : G1 e1 i3 \* C" s
  if ((email.charAt(i) == "@") & (email.length > 5))     * F7 H. D4 y' O+ N
   {     
" l+ P* A& |9 o7 x& _9 C     emailerr=emailerr+1     * V( ?) S; I# C, [9 w; ]
   }     7 Z% e+ A) p! N( e1 h  N
  }     
- ]) z: z/ g+ W5 t4 K, H* k if (emailerr != 1)     
8 [0 [2 G" W* _8 G9 M& m+ H  {     1 M- ?$ A4 S' ]2 `3 h3 X1 e
  alert("请输入正确的E-MAIL地址");     
4 X! i9 z+ x4 D& Z- L! F3 Z  document.sform1.email.focus();     
) w( W" R0 p( A( _/ r9 G  return false;     
- C2 i+ s/ `5 Z7 v$ V  }           
" c& ?7 b  H, g! \  
! x; T# X- T, F8 ?" ?/ J2 J if (document.sform1.checkask.value=="")
! Z  J( |7 ]* U* b- G/ l  {
# r6 a4 l: ]! b9 S4 U/ v   alert("密码提示问题不能为空");     4 J3 [7 e, r! _# F
   document.sform1.checkask.focus();     
5 P. H5 ~1 D% u   return false;  
# d/ ]/ q5 I" T- \  } 1 _% M/ T; F* W# R7 l
if (document.sform1.checkans.value=="") 3 ~3 ~! [  c3 v# C
  { % \2 A# W8 d0 J4 F* O) a; o% b
   alert("您的密码提示问题答案不能为空"); " e1 p7 x% Z3 Q0 q8 l: C# W
   document.sform1.checkans.focus();     
7 d+ A! V9 k! Z  ?5 b   return false;    n4 t% ?2 N: Z; ]" B; E
  }
# Y8 \: g* e/ S, ^ return true;     
& ]8 u: [  q4 U$ p  }* J     0 R/ {7 o1 D7 d+ W0 J% g
} & r7 t% q; ]$ o7 {! p  G3 d6 G
</script>

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