返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
5 K: q4 g% ~' c# o7 j1 A$ R<script language="javascript">     - [4 Q3 ~9 B4 g5 Q# h  q8 t3 w
function IsDigit(cCheck)     9 ~  z7 W) H& |# P$ x4 E5 K
{     3 `$ r' Z& ^9 v( i/ }0 h, K; @
return (('0'<=cCheck) && (cCheck<='9'));     7 B7 b4 ?; _. \8 F9 C! R3 |: J
}     
  l! r) \9 t1 J+ A; J0 a" D; \     
2 P& D0 m0 D# M  V" M+ \$ E( Xfunction IsAlpha(cCheck)     # s; _- \; @  n6 w( V  M, h9 T* G8 _8 w
{     $ p) |3 ~+ I5 h1 r: P- X% E9 f
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     2 o) i$ F* `1 \3 W- q" K" y
}              & N' Y7 E; v# K$ ^! G  f0 [0 d" [
      8 p) L3 p2 y) x; b7 Z- D+ R
function IsaNull(cCheck)          $ E# O4 z" S# w
{          - J5 ^3 S. P( O7 |) B, n3 Z
return(cCheck != " ")         
! a" n0 O5 j8 t  H" y }                              
6 ]' Z) }8 N& C      
+ ~3 d. x2 o: F8 U0 S# b8 Afunction checkform()     
  E2 a4 Z0 t: y0 Y& j{
5 h  C2 C5 X$ z  id = document.sform1.id.value;     
# z( @) I3 x8 D8 `7 q if (id == "")     $ Z8 A: {2 i- A$ n$ E" b
  {     . C/ S2 z  w' I1 E1 E' v
  alert("请输入注册名");     0 ]! x) ?+ V5 h& a5 n) y+ m5 \
  document.sform1.id.focus();     
% k8 ?4 _5 L6 b8 K. v7 I9 A  return false;     
: l+ L$ c# ^0 w3 @" S  H1 e  }     
; o" l& m/ `8 b, t* s' p     
, |  o9 Q% {6 K4 e4 x# E2 ?$ J for (nIndex=0; nIndex<id.length; nIndex++)     5 F+ p$ t6 Z* [
  {     
* i7 G. k& s* [1 L  cCheck = id.charAt(nIndex);     ( J! R& b9 Q9 ^
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ' p. C( k; f; {, \. v
   {     ! U* r' I6 A2 R5 a. f4 F
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     5 y8 H" Z- H! Q# z/ d5 ^1 U
   document.sform1.id.focus();     
" U: J* b( t- p$ W/ t3 M1 o   return false;     
$ I/ E3 h4 \$ A& Q- n& c' l   }       I# f% z& ?1 Y: ^: e: g  B2 _
  } $ E* q0 W* \* h- V
  chineseid = document.sform1.chineseid.value;     # M9 B7 c! `( w7 o8 o' }
if (chineseid == "")     
3 @- p* ]; z! R  {     
0 O& T) ?! y' m* Z# T5 C% ?  alert("请输入中文昵称");     7 |) p- O, w8 [4 a. O7 v+ q
  document.sform1.chineseid.focus();     
- ]9 f1 W% B" r0 W$ }  return false;     , i9 V4 T7 S4 E! Y+ x( U
  }    0 h" R. u/ ?, s) P
password = document.sform1.password.value;     
" c" i2 N3 u" b0 ` if (password == "")     
% g$ {8 b( T( U  {     3 G6 x4 c7 `5 n! L7 C4 f
  alert("请输入登陆密码");     ( c/ l& J0 z0 Z; L
  document.sform1.password.focus();     7 }3 g6 {9 Y! _
  return false;     ! `$ \7 P" R7 z0 H
  } 9 n# |  s3 l! m4 J/ Y6 q* J" t9 c: H
password1 = document.sform1.password1.value;     # `6 E* ~6 x. d
if (password>password1)     $ c- a/ r) R# }  V
  {6 ?7 }# F$ E5 @8 W/ N4 a, |
     alert("重复密码与登陆密码不相同");     ; h3 B  E. I: L  {  j" d4 |6 ^
  document.sform1.password.focus();
( x; J3 E& D5 [: h" S( r6 V                                document.sform1.password1.focus();     
5 H. t3 T! H) P  return false;8 |2 A! {, S0 m" R$ n2 T1 e
  }  ' |8 s% V) `0 M9 }* n+ o
if (password<password1)     1 Z2 H, s$ `. d5 M, \
  {/ F5 X2 L" t0 M, P" Z0 D( ]
     alert("重复密码与登陆密码不相同");     / C" o6 s. ]4 _
  document.sform1.password.focus(); 7 G6 V; @( i5 T  Q. w: C! u
                                document.sform1.password1.focus();     9 ?/ ]8 X% N0 l5 i& i# `! Q+ u
  return false;
7 V6 B( ]0 ]0 W6 x, M  } ) |) }3 X) u: b* \- Z" C
if (document.sform1.email.value == "")     
5 }! g3 s1 p- o: C4 J1 P  {     
8 P8 m: e( N0 j: c  alert("请输入您的E-MAIL地址");     % p) B+ K% b# ]2 q7 \1 ^
  document.sform1.email.focus();     
4 U$ `; _0 h9 u. R& \  return false;     & Y7 w1 c  C* x! \& Z9 e! M- N3 b
  }     , \/ Z5 O: {6 A; H; l
      
' k, M1 u# B* U, ]9 G6 L8 ^6 X6 { email=document.sform1.email.value;      5 A0 }7 j  g. c+ N. i8 x, k6 n
emailerr=0     
4 Y# ?2 S! t) d/ ~ for (i=0; i<email.length; i++)     
7 s5 Q& }- y+ u* ~7 @  {     , w) l3 @# N, i2 E. X0 K* \; j- u
  if ((email.charAt(i) == "@") & (email.length > 5))     
% V6 C  o6 F: q" K( t! T5 i4 X   {     , v" L4 k3 I+ g3 n/ z
     emailerr=emailerr+1     
. Z. Z- t: l( U" r   }     6 a' e, B* D2 k6 l6 i
  }     ) N' j) }1 }  g/ f5 M; B2 N9 H
if (emailerr != 1)     " P3 ~! F6 q3 l
  {       s1 p4 i( i" N3 F/ z, ?
  alert("请输入正确的E-MAIL地址");     / V& ]1 n0 c5 V: x, o) j& K
  document.sform1.email.focus();     ! ^) t9 `7 a% v5 a. ~4 l+ c
  return false;     3 f; J% B  C, o9 f1 l+ m
  }           ! i+ d- l6 v$ z/ i. u$ @, H
  & q: _6 P5 U# \8 K" T- S
if (document.sform1.checkask.value=="") ; A- ^* r+ F$ _; P
  { 0 {7 u3 }5 y2 B/ n- q
   alert("密码提示问题不能为空");     3 Y6 D. b4 Y8 Y* M, `
   document.sform1.checkask.focus();     
$ i. S+ |+ @" `: F- |) c   return false;  - P$ V0 }# z" \/ w6 y
  }   d# A" |3 C9 a0 h
if (document.sform1.checkans.value=="") ( B1 _5 u2 _( c$ i
  { : I( U8 ^7 \* u! U( `% i; B
   alert("您的密码提示问题答案不能为空");
' @7 [( T: ]: V2 c   document.sform1.checkans.focus();     
* L4 ^: d6 H' Z9 |9 l   return false;  
& b1 v6 G" W& [: F7 t9 O6 ?  }
2 q5 d% a( b1 b% G return true;     2 w, U/ @9 v0 G' A! ]  [0 Z7 ]
     0 @4 f0 l/ x4 v5 l+ Z% C$ c3 M
}
; b3 d4 ?# d. L% F7 s( Y</script>

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