返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
2 v8 f8 ?, ?, E9 ?% K<script language="javascript">     
0 T5 a* d$ G5 I" `" Bfunction IsDigit(cCheck)     5 T3 |- j: D  n. r
{     
$ {3 ~! C# i! |8 ] return (('0'<=cCheck) && (cCheck<='9'));     
- ?$ i5 l! y6 }7 Y }     $ C# a9 ?! \9 U; W/ ^  a
     
( C3 v! `6 D3 x- F1 nfunction IsAlpha(cCheck)     : j- f3 \, h$ O# n" U3 l& d9 G7 W& g
{     
/ k5 Q4 X; U4 C' \7 L7 G+ x* O  X return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
: z8 _4 \+ ^: J: P }              
3 I' R$ Z/ q' K      " h8 V  ^* _% n5 [- Q% M; Z$ B
function IsaNull(cCheck)          4 V" O. ^" E; ~$ {' k
{         
( `' e* I+ \7 c6 s return(cCheck != " ")         : \) \9 O$ o1 p# M
}                              
9 F( P8 D' @2 D, ~0 Q0 @* S      7 a# A5 I$ W: \, D5 y0 u
function checkform()     
5 B8 ~: Y( c1 m( Y4 i" X/ t7 m& K{ 3 R% n5 r& u  F. [
  id = document.sform1.id.value;     
  U* l( {( Z+ P if (id == "")     / Y' V' g9 h+ `) h* k0 B
  {     
$ C) l  z/ P0 v" R  alert("请输入注册名");     
6 D5 y4 E7 G2 |8 u9 M* w3 }  document.sform1.id.focus();     
; N* Y7 H" z2 x0 l& u6 z; F  return false;     : e2 j& b; d& F1 I
  }     / }$ H/ q2 t! v( S6 ^: Q. S
     
: M; z8 P5 |% D for (nIndex=0; nIndex<id.length; nIndex++)     , V- v8 [) [# `+ K& s( _; }
  {     . E  I. S# }5 S& z$ h4 f
  cCheck = id.charAt(nIndex);     
3 b$ n; V- n# V% [  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
7 {3 u+ A2 Y" c1 z  b# D   {     
& \9 t2 _; D# R0 J8 e4 j% |   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     0 d4 s' R) U9 A. c
   document.sform1.id.focus();     1 j1 C, M) Q5 Q6 S8 p2 w
   return false;     
! @& ^$ R2 d2 q6 p- S$ v   }     
0 {! A2 m8 V' ~" r4 w  } & {3 e" [3 ?+ x
  chineseid = document.sform1.chineseid.value;     ! a. n2 f4 h  ]" f
if (chineseid == "")     
) x* h) ]3 y4 Q. m# D) B  {     , w: Y/ n6 c* L4 j' {
  alert("请输入中文昵称");     
' |" v- E3 V6 C5 u% h  document.sform1.chineseid.focus();     
, ?* g! v4 I2 H, y1 p; ?  return false;     
. {8 [3 F& j7 f) {  }   
8 p6 j# P$ v- F- k) f$ A  Z5 N: O password = document.sform1.password.value;     
! V( V, M2 u: j6 g if (password == "")     
7 I& Y5 Y! O1 v4 }& x$ r/ n& x  {     
  s" e7 C# H6 U% i  alert("请输入登陆密码");     9 b0 |1 g7 S4 e: q) C. E
  document.sform1.password.focus();     
7 }( l- r( ?/ ^' k5 T+ {  return false;     
  j/ B6 Q1 N4 a* c4 p' ]3 L- U" j$ n  }
; v* x8 u  K& v3 z6 A7 \ password1 = document.sform1.password1.value;     
5 [) H* L% |, n. _$ g, P* s  j if (password>password1)     4 ~) R- |+ j. k2 w( E
  {( @2 {7 _# d* v1 X. R) x
     alert("重复密码与登陆密码不相同");     - B  A2 }! }# o2 }7 N
  document.sform1.password.focus();
8 c) w: _. p( w- }, h2 H                                document.sform1.password1.focus();     2 D8 ?1 }! f; C* L* H& k) S- f
  return false;
+ @& o/ C( g- x. A1 \  }  $ i9 a/ Y/ w3 D7 X
if (password<password1)     . T  z  I! i0 }0 v! L" m
  {7 D! D* a6 T/ d. I1 W1 P6 s
     alert("重复密码与登陆密码不相同");     
( C! w2 k; e1 E  s- d  document.sform1.password.focus(); 6 t( N( L- ~4 F2 l
                                document.sform1.password1.focus();     
4 q% f+ ]% G" b, i1 t1 |# Z  return false;
5 M/ I5 u2 `3 D1 z6 G+ I) h( D- I  } / {; p/ M1 J% G* Y3 D# i
if (document.sform1.email.value == "")     
" @! }2 C" C: g& G2 c  {     
! `/ y4 O: ~! z- Q% m0 {. U" W/ x  alert("请输入您的E-MAIL地址");     
) v9 ^: S6 `9 P; g  document.sform1.email.focus();     # e" ~  a# Y1 H9 B- a4 G! d
  return false;     * b" J, o" C$ x: F* T
  }     
9 }  e# `, F& C9 m, u& }2 z5 [/ H, A  Z      3 S8 s. k/ N* s. F: @
email=document.sform1.email.value;      : w2 Y# N2 a& X3 K# q0 |
emailerr=0     
) H5 U0 t; E' u( e# N" y for (i=0; i<email.length; i++)     
1 _# g. r  q# Q7 w7 I  {     
1 M4 E3 O1 b  x6 _# I  if ((email.charAt(i) == "@") & (email.length > 5))       F' i  f- j0 t: n7 u
   {     
! A+ L( t, A& A0 j+ _2 [! m     emailerr=emailerr+1     
. \4 a) L5 f5 e$ V, d   }     / o+ j+ j3 z& {0 T+ G3 j
  }     
! d- W) _: b$ n9 e) R+ ?5 M if (emailerr != 1)     4 P7 I( C) |% `7 N' S: J
  {     
  I5 Q9 ]+ `* q$ }( F; W& n' l/ {  alert("请输入正确的E-MAIL地址");     3 l1 ~% T. W; H' l! t4 f/ z0 i; |
  document.sform1.email.focus();     $ S+ G5 q. T6 P7 W: v# a4 R
  return false;     
, C6 m$ B9 W! I1 n' I* k' g9 }/ O  }           
/ o8 Q5 n# U9 |- L1 l& e% t2 w# l  # p& V) A- I6 C% v" z" C
if (document.sform1.checkask.value=="") ; U$ C: Y6 E- c  w. j
  { 8 b6 T! a+ f3 T& x' X6 }
   alert("密码提示问题不能为空");     , Q7 e; ~* o  Q
   document.sform1.checkask.focus();     
* G) V5 B! {2 X) b  N6 [! l, M% n   return false;  
! C" l8 l* K' B- F  } ! R+ t9 q9 `1 R. [" V9 z/ f/ i* Q
if (document.sform1.checkans.value=="") 6 W; L) h: E' A( y6 x+ x7 Q
  {
' z2 r+ [2 W0 O5 w5 B5 V5 g. y   alert("您的密码提示问题答案不能为空");
$ i( o8 T. @. i* R1 ?: Q   document.sform1.checkans.focus();     " g6 Z+ }& Z/ {3 ]. ?, a) _, h: G
   return false;  
+ `6 X) m6 P6 R+ ]4 _5 I7 F% }. W  }, A4 g* L' b5 L
return true;     ( _: B+ m2 [% L# a
     
8 F! b9 x# n$ F2 R} 1 n6 C# B! C# h
</script>

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