返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
$ @$ i  W+ }$ I# y3 c# N% I" g0 n<script language="javascript">     8 }/ i* k. H! @- Z
function IsDigit(cCheck)     
: W2 t. `6 ]% {$ E& h7 A2 n {     , a& A# J0 M. u* X4 e
return (('0'<=cCheck) && (cCheck<='9'));     
4 F! {# ]9 m) q' R }     
+ x9 x6 \3 c) ^* I+ d9 _* x     ' {7 Q- i. g5 i0 m% x) v( R
function IsAlpha(cCheck)     $ J% G) V% p: V& ]. ]
{     3 B: d9 U! |- f1 k
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     & b. b! B0 C( k  y+ ?
}              ) ^1 }* x, Z" y& L0 g, B
      
* j3 K, n2 ]# i% G* z  B0 hfunction IsaNull(cCheck)          $ f( R3 m& H, \3 S- ?+ S1 R
{          + M# m! {6 L  u" y' e
return(cCheck != " ")         ' Y- |# e& D7 ?+ l# ^( y
}                               , _- Q0 X( ?; k3 r) e1 ?( F# c- h% I2 b
      
: ]3 I; c- K4 e) F5 u( U3 W9 c7 Wfunction checkform()     
! J  u5 I1 ~' s- u( l{
$ r- m  D" B! P; [" [! M$ Y2 N  id = document.sform1.id.value;     
( Q, ]2 ^3 b. L& o if (id == "")     
0 A8 t/ ^0 K4 R% G& {. `! R- t+ X, a  {     
) y+ l) G, I9 ]5 `2 G/ t% h9 c1 v* p  alert("请输入注册名");     , _( o1 V. j& Q- _, m
  document.sform1.id.focus();     ( z  _) h6 L5 @0 {
  return false;     
1 E/ f7 C0 J  y2 ?% n  }     
+ T" o3 [; T8 P     ( k! j/ P1 E3 `1 R, d
for (nIndex=0; nIndex<id.length; nIndex++)     
. P8 x' Z6 e9 C; P9 t( E) r# X  {     
' J' ]8 u- N% ~: m  L9 t  cCheck = id.charAt(nIndex);     2 V  c( v) S6 u$ s, c* s1 }
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     4 b4 _2 H6 e. P2 d' i
   {     ( k- ~7 E: {7 v* b6 b; \5 B
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
6 Q6 O+ r. t9 f0 u3 c2 N5 P& e- w   document.sform1.id.focus();     $ Z# D0 z. ]2 Z
   return false;     & J  W- O% b9 J& r
   }     & d! X2 J( s. E8 L7 s
  } 9 I: p+ @8 \3 {7 t* [$ y2 g
  chineseid = document.sform1.chineseid.value;     & g1 s4 e( h9 N) E: S
if (chineseid == "")     6 |  A# t$ C5 f: }" G
  {     7 M6 O8 A" O& C7 Y% {# [
  alert("请输入中文昵称");     ; S7 L+ F8 v: v2 F' J4 ~  b
  document.sform1.chineseid.focus();     
9 q# `0 ]- G8 q/ b! S& q* R  return false;     
8 V( \& ^, q. y$ w  |  }    + y  D2 K& Q" z( @
password = document.sform1.password.value;     
2 x0 U* V4 }, D( l6 z if (password == "")     9 l# j) i: ^6 @: E& r! {! t& M
  {     ; \: `& k4 p% @  E( m0 n8 o) |8 j
  alert("请输入登陆密码");     
/ K& x- s$ w% {. G- n  document.sform1.password.focus();     8 o; f% Z  \% T/ z( h5 w
  return false;     
- K( [7 G7 o+ V  }
7 G- u$ D  ?$ Q9 A. E* F" {( R password1 = document.sform1.password1.value;     
7 C/ P8 b3 |% d2 s* W if (password>password1)     9 |7 \& m' V7 |6 P: s# p$ F
  {
4 l+ ^! r, _+ h     alert("重复密码与登陆密码不相同");     4 g+ g4 ^' L8 y" `5 {3 t4 c! j
  document.sform1.password.focus();
7 B" Y: y5 _( Q3 l                                document.sform1.password1.focus();     
5 t7 D# R" B; u. Q$ h' p  return false;
4 i$ t- l* K5 O5 c  }  ! E) |& p0 m# d# \; c. N) v3 C
if (password<password1)     
9 w, g) `. H- Q+ \9 o& T  W  {. l1 w6 J0 {% m# b0 [& P/ K7 [* G
     alert("重复密码与登陆密码不相同");     9 e0 `$ \/ T- l' m1 n9 k
  document.sform1.password.focus();
% N& {3 U5 ]' g( w3 l; U                                document.sform1.password1.focus();     
! h& j/ S' m. t0 F5 O" A  return false;* N$ {! N# v. Q7 r( X
  } " ]# @0 Z2 G, F4 H+ a
if (document.sform1.email.value == "")     8 F2 B9 k+ e, S) B  o
  {     
& I7 W) E$ D; _* ]! q# |( C. u9 x  alert("请输入您的E-MAIL地址");     
" }2 z  b4 V7 h* Z  document.sform1.email.focus();     , N# ^0 T% ?. {! l
  return false;     & s" Z. J+ ^  a3 s1 \0 D. Z7 w- F
  }     $ j# x, ]# c! o' C% O9 `
      ) k1 H0 C% q  t. z$ t
email=document.sform1.email.value;      1 r( |6 W( H% F3 X5 L6 j
emailerr=0     
; U; d- j, z) i* D8 O9 T, l for (i=0; i<email.length; i++)     
7 ]4 k1 i0 S% U1 W2 [  {     
' e7 R3 h4 }0 i9 S9 s  if ((email.charAt(i) == "@") & (email.length > 5))     
& O7 E0 ^8 z0 a" U% X   {     ) D3 I7 y. q2 y) m, s; l8 [
     emailerr=emailerr+1     # ?8 t. S+ Q; M- ]
   }     9 R& i7 [  M/ p8 P
  }     
4 ^  l2 J) U0 u% m3 N. u if (emailerr != 1)     2 Y# C$ B' ^' ?5 `
  {     
. M9 d* U: {( ?; a  alert("请输入正确的E-MAIL地址");     0 O' n" i/ p  m% B, f( m" H
  document.sform1.email.focus();     
" @' d2 ?) X  e  return false;     ) C8 u: b2 l6 S
  }           : v) w) l* c  K# T
  1 |9 |% m) k6 b% c
if (document.sform1.checkask.value=="")
$ U) E: `8 Q; O9 _( a( L; H5 g  {
8 S: _: `8 Y8 y* M5 ?; T/ f. `. F   alert("密码提示问题不能为空");     * Y5 J; R+ g8 Q
   document.sform1.checkask.focus();     
/ k/ ~2 ^3 O5 p: M6 r   return false;  4 K" j* f( _5 s/ ?( N0 d6 L& \
  } # G% S7 w. a! K# r9 ?
if (document.sform1.checkans.value=="") 2 R: i$ b2 ]: G; w% a0 Z
  {
3 k+ p. F% d' a- {! |! `   alert("您的密码提示问题答案不能为空");
2 |* y3 f( E* k6 k& p" A* J   document.sform1.checkans.focus();     ( \$ k& @9 `! o) u, V
   return false;  
4 A4 F5 e' H0 _5 i- w  }
2 f5 p( s* z1 ?8 f9 ? return true;     + A/ X* ]/ M5 [) h2 H7 O# c4 n
       N  `$ R- Q8 m. i1 V: U6 D- o6 l
}   Y) @( R3 K9 t, ?# h
</script>

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