返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:+ O* F% F, r# b$ B" n7 X% k  R
<script language="javascript">     , _. D1 l4 b' I0 X9 {
function IsDigit(cCheck)     ! ^  j. B( S$ H0 x9 ~. k
{     
, G/ F+ Y2 K8 s% ~' e return (('0'<=cCheck) && (cCheck<='9'));     4 D$ E: S$ S1 T: r
}     
3 \+ C( O2 B2 j" g  n- L0 X# p     
* P9 _4 K! L" C  V' F6 g% `' }function IsAlpha(cCheck)     6 B$ `$ D  F! x' j" C9 e
{     
; i2 U1 S! ~% `; R9 \ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ( Y) R0 B# F. r' X9 z- t' \! v
}              : b; a3 h1 K: a; Z
      " s! P6 \  I  {2 \) V
function IsaNull(cCheck)          / [6 s& e' x# O! a
{         
. W$ e0 D0 @1 G+ | return(cCheck != " ")         
$ q! T- \4 D  t: |! H5 s }                              
/ |4 U( m: P  T      
+ P, e! w7 t, _4 k7 Mfunction checkform()     5 T% E4 q/ A$ p  I1 r, T
{
( z" p9 E* W4 r2 N$ b  o% N7 z0 @  id = document.sform1.id.value;       v. M$ J! O( S+ o; Y" C8 @( B% H3 [0 c2 ?
if (id == "")     0 U8 m% r' n% c6 I! r: v
  {     
- p8 K( L+ Q; ^0 C5 n' f  alert("请输入注册名");     
5 |8 f, r- S7 ^8 ?4 V  document.sform1.id.focus();     - E% F; b, ~! m
  return false;     
2 j4 Z2 r. g; v  }     * {6 |- j& s) Q! Q
     , i# Q2 {5 \+ a- v; N
for (nIndex=0; nIndex<id.length; nIndex++)     
  t& E$ _. {! t# y3 X0 A8 D* E  {     
! C, u" u  v6 n2 j3 \  C  cCheck = id.charAt(nIndex);     
, n0 y* d5 ?' h/ A9 f  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
: L) [$ x% l/ v/ @5 K' w- ^   {     # e$ G$ e8 ^& p  `" ^/ [
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     1 R. x4 t7 ~& l$ t
   document.sform1.id.focus();       |  y* U* l9 K: L# P; t9 m5 m
   return false;     
. ~7 q5 l9 a( }   }     
* F9 S. j) M2 d  } % `% R' t6 \& H- n
  chineseid = document.sform1.chineseid.value;     
, I/ M6 n# k5 @) L/ O& G- P. z1 n( B if (chineseid == "")     " }$ C& s- J: I' p1 ]
  {     2 a0 E# g. K6 D  E6 l+ D
  alert("请输入中文昵称");     
5 i: T  o/ X8 z' n! g# L  document.sform1.chineseid.focus();     2 V5 |- `5 h) @4 E! x
  return false;     
" L& }/ {8 T4 F, U: G% b  }    6 v6 q( S/ r4 `( |0 r* b, \8 t/ f, N
password = document.sform1.password.value;     
! E4 x9 r$ @3 T3 `" O& m# z! e if (password == "")     3 Q  I6 }0 _( |
  {     8 Z4 T6 D! Q( j! d  k& n: x4 A+ ^
  alert("请输入登陆密码");     4 s7 J, L9 B( t+ u: a# [( @5 o
  document.sform1.password.focus();     9 a1 m. B7 q; V9 j7 n! k
  return false;       c& m: n2 [% R3 q
  }
- ~! X# k# @' _ password1 = document.sform1.password1.value;     
9 x/ d8 u2 y* z" H+ }; F if (password>password1)     1 O. P! }' M! i2 ~7 ^
  {) V' d) Z4 M0 {, }& D
     alert("重复密码与登陆密码不相同");     
; I, h( ?( \7 _3 y! p" r, t# a+ R  document.sform1.password.focus(); ( }0 z" Z( Y4 Y- q2 j
                                document.sform1.password1.focus();     9 C( X3 z! F7 v2 ?2 A) k. ]8 {
  return false;6 X; q4 r/ X& a0 c+ o2 c+ c" ]
  }  
. C- K2 i) p/ p. X5 h: L4 h* tif (password<password1)     * J/ m9 x! v; ?& ^" z
  {7 U( t( b. K7 ^/ p" q' @& S
     alert("重复密码与登陆密码不相同");     . B& F( X5 B( a
  document.sform1.password.focus(); , k4 L6 o  m7 G- N+ Y# j
                                document.sform1.password1.focus();     
, m1 |! K& V. C/ P- o0 E  return false;/ F2 }- Q# f' f6 j
  }
7 v  b# p% {: _" o if (document.sform1.email.value == "")     5 o- V8 ?( P) J) A0 ~
  {     9 D& `2 B" R6 H! ?3 t
  alert("请输入您的E-MAIL地址");     8 ~- Y1 {: w# ?# t8 `( R
  document.sform1.email.focus();     
, J; K2 P) d" g  return false;     ; O4 S. w$ B: W2 ^5 Q& I* F! K
  }     
1 c/ i) A3 c' C( C9 F5 L      
3 t7 r  d& \/ z* [ email=document.sform1.email.value;      3 }" Z; ]# [& x9 e8 @0 w* _3 s( [0 Y
emailerr=0     
& a5 \/ W) ?. U5 E# v for (i=0; i<email.length; i++)       o! p9 R! a: M2 ^# ]0 m
  {     
. @6 C/ K. G$ d( ^- E- |  if ((email.charAt(i) == "@") & (email.length > 5))       r) `4 Q% Q; Y
   {     
) t9 D3 G( A  ^# d0 [/ ~# \     emailerr=emailerr+1     0 ^9 \' \& l# `4 b- f& {3 E* U  ~  t! d
   }     
" H5 |" L& D4 s: d5 ~  }     
2 S! l$ _4 S3 E8 g/ a7 \3 h if (emailerr != 1)     2 R7 O# y. a4 z4 z* A  {
  {     ; X- z; Q7 _! d+ H# A- Q6 Q
  alert("请输入正确的E-MAIL地址");     3 P1 P8 ]) T; M1 Y  r& g/ W* C
  document.sform1.email.focus();     9 @7 x7 ]7 I# `+ T9 V" I0 V0 e
  return false;     
: u. i2 C8 E: Y8 g" c  }           
! D2 \; _2 @5 N- ^4 K  W  
2 `4 m) z$ j6 {) M5 z  W* ~ if (document.sform1.checkask.value=="") 9 d: K3 L" m- m4 u  q/ z
  {
6 |: [4 @0 C; P0 b6 `2 g   alert("密码提示问题不能为空");     : T9 h* K: t* m/ X" J0 n
   document.sform1.checkask.focus();     
6 G3 b4 m6 f7 |6 h/ c% B   return false;  / v- m- g/ v: B) ^1 R# D  ^  _# l. e
  } 4 R" H" Y9 j1 |, m6 F, E' \
if (document.sform1.checkans.value=="")
& y" b& g5 U2 i4 J! E2 M: i+ C/ E  {
8 Y% v. D0 [0 B8 {: h3 z9 z1 `   alert("您的密码提示问题答案不能为空"); 5 V2 O0 |( S. t/ S$ h
   document.sform1.checkans.focus();     
- [" q, j" ]' f   return false;  
1 y8 B& d' h  O. g0 G8 e  }
& K4 N4 O0 f. q" P return true;     . p+ P- A, Y1 B, P4 }
     
1 w4 |3 I/ c: q+ L, W3 w}
2 t3 s# s$ Y/ P: X2 O</script>

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