返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
. W2 S. c% `+ i3 l( N* Q<script language="javascript">     1 Q9 {" f( w! X/ \
function IsDigit(cCheck)     # s  b0 ?# W% F6 X6 K& h/ W: S9 J
{     
9 s2 t& ]1 r. T4 v' W( |" N+ W return (('0'<=cCheck) && (cCheck<='9'));     / w% Q5 \7 Y7 x- \; \  r
}     # _% S5 d' C' o3 R% p
     
( g" i. A! V  g+ |! Pfunction IsAlpha(cCheck)     0 Y# x0 S* z& c% e& {7 y
{     
) e% D1 n- N3 ~0 F6 O0 L return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
. J) U. G: G" k+ {, w0 O, n }              
$ P; b/ h% _% a; C9 x& L      # V' I, U& H) W1 d: }# c# G2 @7 s+ x4 e
function IsaNull(cCheck)         
9 I7 N' o. |% Q/ D {          ! s! Y# U3 {+ q
return(cCheck != " ")         & r+ M# X( @9 x6 M
}                              
$ a( ]5 |6 b  ]* j6 c      $ _+ K+ f5 o) d$ f9 ~
function checkform()     - O6 `# V+ {# y3 m! v
{
# A* [8 m4 J2 Z1 Y  id = document.sform1.id.value;     2 l2 c0 U% G# E4 t; `$ l
if (id == "")     / X8 C$ R7 ^! g$ c) U
  {     
; C: n& H) z1 n' e; ?( `  alert("请输入注册名");     ! F, b0 G8 n8 u/ \7 Y2 \2 c3 [
  document.sform1.id.focus();     
( Y* U4 _, d" h& w' j, N0 k  return false;     ! p; x" d8 n+ J" J- s% n
  }     - S# R. b% n& z, Y
     8 f2 f" R* [1 R" ]1 {% J
for (nIndex=0; nIndex<id.length; nIndex++)     . b4 C) u' n: _3 p5 [. \5 Z7 h
  {     
0 P, y1 @- ~" a  cCheck = id.charAt(nIndex);     
- S1 x; V1 ^8 y( s  d  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     9 s& r8 E2 O7 E- a' Q( ?# Y% D
   {     8 @* X# `. W; O; B" @( C9 Z% `" f
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
! K( h$ o1 j# g' Z   document.sform1.id.focus();     0 N' e9 ~) N3 O- z) Z
   return false;     ! @3 Y0 E2 i* d, u1 M& h* j
   }     
9 u( b4 n4 P9 q9 T3 G8 m( }  }
  _6 A9 c/ O, W  chineseid = document.sform1.chineseid.value;     
9 u; I  {1 l, R& L: v- E if (chineseid == "")     
0 A0 l6 N2 Y+ C: E& y  c  {     " _5 I% H" s# Y, D, F
  alert("请输入中文昵称");     " L, ?+ l$ H! t
  document.sform1.chineseid.focus();     
+ v8 r! s# B9 D, K5 H  @2 ~: ?$ e  S  return false;     ; m  E. u0 D8 W% j8 @' N3 s( u& Y
  }   
& |' P6 Q9 Y! {) `* m" e password = document.sform1.password.value;     
( e; R9 s" S+ d if (password == "")     
( f. h! M' @( V9 e  {     ! y" q) {. M. L3 R. Y
  alert("请输入登陆密码");     
: g0 b) n! G6 I8 f" c+ {  M  document.sform1.password.focus();       Q3 a. @6 [1 q
  return false;     0 I0 c9 m; @( B* t  w$ x
  }
: N; H& ~5 m, a+ I9 A password1 = document.sform1.password1.value;     0 m# w! a5 W$ P
if (password>password1)     
. W* o# R3 q. @  {
: Z; X+ v- R. i# S( P9 k     alert("重复密码与登陆密码不相同");     * f/ _+ S" A, w; u# R
  document.sform1.password.focus(); ( m% a( A5 g5 ~- s$ I; m4 p
                                document.sform1.password1.focus();     
  a. E' M; P: O* ~  p& N! y  return false;
' S. F9 h1 {8 b6 C; ]3 u  }  
* v9 c# m1 q( K5 ~. O* f9 H- ]6 Kif (password<password1)     - @; U1 T! s1 L- H; s
  {5 w% g, }- I1 @
     alert("重复密码与登陆密码不相同");     $ u" s3 g5 `7 ?6 [6 I+ X
  document.sform1.password.focus(); * N- y0 l+ j# P4 @& \$ S
                                document.sform1.password1.focus();     + R1 b' z7 F# d/ G& G
  return false;3 U" j! O6 a3 L; k% m
  } ) J8 ?# d! s9 g! g1 O* \# I! M
if (document.sform1.email.value == "")     
7 V) |/ L% ^4 g) e! N7 \$ l  {     % C# j2 W& T' ?5 O1 R$ h4 q5 _
  alert("请输入您的E-MAIL地址");     
1 A" t" o0 L; e* D. a  document.sform1.email.focus();     # H5 V0 i' M! N9 g
  return false;     : ~, f3 I- d1 x  u
  }     " W7 E2 n) C9 M$ _
      7 B8 p( \5 O; ]
email=document.sform1.email.value;      & V! {6 `2 ?2 B. P0 t
emailerr=0     5 }' E0 {# p( ~; f% z; U
for (i=0; i<email.length; i++)     1 J0 g8 t, u9 w1 O* r- b- A
  {     , {( H& i! G" G! T4 y( |) s
  if ((email.charAt(i) == "@") & (email.length > 5))     : S7 f( p2 s3 V* X! V) A3 i
   {     2 q: q- g, D3 p- ~
     emailerr=emailerr+1     
: ?" t0 s: B8 G   }     
4 x) H' t) J- R4 F, X  }     
+ p5 ^0 O' \' D) ?0 V if (emailerr != 1)     ' J- q" ~' b& |$ \
  {     ! `( v! j7 V" u" R% x
  alert("请输入正确的E-MAIL地址");     * @: P% w8 L. B$ k+ j7 M: q  M
  document.sform1.email.focus();     
" k7 d6 j; i- k$ P  return false;     
0 F* c" a: I! S5 j, p  }           " t) ^0 V! d- w* K7 z
  ' `# i% }( t4 E; |9 u7 {4 H% m8 n
if (document.sform1.checkask.value=="") 4 b+ e5 {) j! J$ s# X
  { 3 u3 t0 m0 U) a8 V
   alert("密码提示问题不能为空");     
; O  @! I- @5 v9 b6 X   document.sform1.checkask.focus();     # W/ }9 L6 U7 v& p
   return false;  
2 I: U$ B" s5 k. }( b3 {; u, O3 k  } + @$ e6 X7 ^. Z* Y" O
if (document.sform1.checkans.value=="")
  B- ~, I2 w5 ~  {
2 c. d5 |# M1 A* a8 e: ]   alert("您的密码提示问题答案不能为空"); # L4 D. w, x" J
   document.sform1.checkans.focus();     
$ n) y) L9 M" a. R2 N1 a   return false;  
- s1 l. d# y2 O1 c/ O' ]  }
1 Z5 f# }9 o% @ return true;     : q& w/ M( r7 m, E3 H" g+ N) O
     
8 b6 G% f: P" r+ z  a}
+ A% L1 D9 |% B6 v7 Y0 x</script>

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