获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
! k+ [( Q) H( a5 ^* a. }2 k<script language="javascript">     . ?5 |+ W0 X: f0 c! q: K0 o, r
function IsDigit(cCheck)     ! C1 @( x+ O* ?+ n
{     6 ]0 D+ }) G+ c6 A. e+ v9 K
return (('0'<=cCheck) && (cCheck<='9'));     ! I2 |$ U  T1 ?1 @
}     ! i; s" Y8 s, ~  M' @+ e" m
     
, a  a  v: y3 g- T) M/ u9 z, Ffunction IsAlpha(cCheck)     
- ~1 N* ^0 C' Q/ t4 W1 | {     & {& U+ W  O- V$ n* ~6 G0 d
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
9 x5 o$ S2 L+ N% ~9 R }              5 j2 B$ t2 B  D4 M0 j- \
      
9 x+ F( |$ ]0 }  s% L! U1 Jfunction IsaNull(cCheck)          : N/ `6 ]9 G4 {- a
{         
- @' _! z6 V6 i& T4 u return(cCheck != " ")         , z8 d* d9 h' ]( S2 e
}                              
, m# A  i! J; L6 D" V      
5 B& M1 r. d- w# u# `# Jfunction checkform()     * M* l3 E3 [* j7 c
{ % V. h7 [& |+ V  ?  f% x
  id = document.sform1.id.value;     + w3 O! f; b5 r4 S. V
if (id == "")     
2 V" e, t& G. V. U# ~  {     6 b% Z4 B+ k& v0 m4 Y( J9 o3 k
  alert("请输入注册名");     & d7 p. M5 u  ]; j
  document.sform1.id.focus();     ! R: k0 @6 d+ K& n! Q# K) m7 X
  return false;     8 R6 Z6 A* j; g0 B
  }     ) ]+ i: D% ^4 P, d+ O6 U
     $ a# Q0 x/ ]8 [1 j5 ]. m: X
for (nIndex=0; nIndex<id.length; nIndex++)     2 g$ u' @" L: M2 L0 ^5 c6 H
  {     - ^- ?$ c$ @$ s; f; s
  cCheck = id.charAt(nIndex);     - r- s) s* M9 ]  R
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     4 |2 {& N4 R+ R" ?5 F
   {     
' R) D7 L4 j4 m6 p   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
6 z( Z- j% h: [" [! T5 s   document.sform1.id.focus();     
4 s1 C0 d' W' }4 X9 z   return false;     
- V5 X% o; d8 \5 {1 o$ }, f" w   }     
- i% l0 f  L$ m! P7 q  }
) t  d. ]( H$ y  E2 k$ |9 t+ }& t  chineseid = document.sform1.chineseid.value;     
; E0 n2 t' {& \$ \- h* m0 @ if (chineseid == "")     ) A! J- R9 T% d* M
  {     ' N' \" y( v# I6 I9 ]; O3 K
  alert("请输入中文昵称");     / A0 c; q; H3 b  @" a  p2 W8 H* J3 v
  document.sform1.chineseid.focus();     
7 j0 R% u% I* B6 m2 A+ m/ c- u  return false;     
5 {0 d- f4 V% Z+ |  }   
$ E! a' m7 z+ X8 S; V+ d& C. E password = document.sform1.password.value;     
- c# Q1 V) s8 t if (password == "")     
& m0 C7 Q) k. c* O/ a( [' H) y. P  {     ; J. i/ b! g# \% w
  alert("请输入登陆密码");     1 _& n; w1 l8 `
  document.sform1.password.focus();     3 c7 ^( M6 f7 D6 N: u
  return false;     ! ~; n& G3 O8 K1 U0 C
  }
5 q8 z" v! ]( `/ B+ L) Q+ B password1 = document.sform1.password1.value;     
' N! d3 ^9 \7 ?9 S  @ if (password>password1)     
3 ^$ J' ]3 m/ }& F  M; f# A* j  {- f6 U1 v3 b! Q7 a  k
     alert("重复密码与登陆密码不相同");     , `& p9 a: p0 v# H7 ]# n
  document.sform1.password.focus();
$ |2 X5 ]8 c; I: d, p                                document.sform1.password1.focus();     
! x5 ?3 R$ b- v  w8 O+ n  return false;, h* \0 g6 \: g4 z
  }  & T+ _, u7 X6 N4 z5 R( Y
if (password<password1)     ! W" |- I3 b" G9 P& U' @; d
  {3 ~5 b& ?9 q0 q/ K, L
     alert("重复密码与登陆密码不相同");     9 n+ _- Q, ~/ ?$ J# q0 Z
  document.sform1.password.focus();
3 y6 l- D" _' F+ z                                document.sform1.password1.focus();     
7 g' e, z) O' J; U' ]  return false;
+ e* o6 |6 o% m; H! f0 E  V8 _  } * I  H  }& ^8 \/ n, ?8 I. x" B5 z4 L
if (document.sform1.email.value == "")     
% }6 G7 \( S7 s& s9 D  {     
3 y+ n8 A/ N$ A1 s* h  alert("请输入您的E-MAIL地址");     ) e4 V* _, W; v' k! o% h  U
  document.sform1.email.focus();     
5 k: a: J+ p* ]1 Q( D+ H6 r  return false;     : x# L1 d1 D( O0 I% I
  }     
' M/ Y" N' ], Z4 Y9 B      
) t8 O+ g: \* \$ K7 }: d# e email=document.sform1.email.value;      
1 S* b0 r9 D( Q- \5 j4 j emailerr=0     & F( h; B* ^. o7 G3 v( m  f8 t! z
for (i=0; i<email.length; i++)     
- E* ]2 ^8 S/ n  g  {     7 s9 O6 c5 t& v6 R" \
  if ((email.charAt(i) == "@") & (email.length > 5))     " ?% Q. m; s% X0 Y6 s
   {     * Z$ t- k7 F4 k' m
     emailerr=emailerr+1     7 U3 R; J( X& ~7 \" e7 A* ?. w
   }     ' C# ]1 M3 n% F/ i) c/ \
  }     # U: A) q4 d5 V- [' \
if (emailerr != 1)     1 Z3 l* K1 ?  [  U0 u
  {     
8 w% j1 o- e* p+ ]% G! i" ~: D  alert("请输入正确的E-MAIL地址");     
2 L9 p# C$ v$ X/ E2 D6 {6 D  document.sform1.email.focus();     ' A: ?$ n' u9 x# H# ?* |/ `9 ~2 G0 t# o
  return false;     
. `: B! H$ B# p5 o. l* T6 A  }           
8 [) j2 M* O: T8 c  9 |% \* p6 `  w# f2 T
if (document.sform1.checkask.value=="") / f6 d1 q7 l- @
  { / D; H( l5 B: B( A, b* m
   alert("密码提示问题不能为空");     : K( `3 U; z3 d
   document.sform1.checkask.focus();     
6 E$ {) B* [& N2 ^   return false;  
4 R6 L  k6 _+ G7 V- g# `6 v  }
9 c  ?$ [1 K# \) B4 E  p if (document.sform1.checkans.value=="")
- _3 C6 C. V6 W5 N, M  { # w7 `! d) M0 z1 N! [
   alert("您的密码提示问题答案不能为空"); 3 u" p& T7 j5 r' W. L+ t( G2 \: p
   document.sform1.checkans.focus();     # ^# ^/ j$ ^  O2 A" ?
   return false;  : `4 Q$ G3 e" D! B% ?8 }2 d
  }
' |9 M, s$ p0 {2 ^ return true;     ; p; c: ?6 }2 i# h; m" {2 S
     . x/ U2 c* t0 R8 {
}
# L4 R, v! b" V$ }3 A$ f# D</script>

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