返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
7 O! y; T& {9 |+ {<script language="javascript">     . l: ]2 O7 f  u8 {. z9 f$ Q8 [' T
function IsDigit(cCheck)     ' |0 U) G( y4 x* \
{     
4 `, d7 J1 x! v' Z1 t5 d) l8 l return (('0'<=cCheck) && (cCheck<='9'));     ' R' _7 P' l, C% Z  L  v
}     
! o  C$ p( W# m& J* E, G2 x/ x: Y0 L/ Y8 _     
& L/ m% x/ `% E4 j2 Kfunction IsAlpha(cCheck)     
7 x5 x2 P% B0 g) W6 C+ ]3 r {     - k& e! H# D$ _9 v
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
' E% W5 q5 t# s2 K# U }              ; I4 n9 Q, S$ c- ~9 q2 V. g
      
/ P  h$ h+ H$ K  V  r- qfunction IsaNull(cCheck)         
7 U  Q9 c' ?" ]! w2 g0 {* i+ i  X {          9 N, S# i4 U0 n6 W! h5 }
return(cCheck != " ")         
% j( N7 V, e' w& E: F }                               9 r* j% k1 T" ~
      
5 |0 [0 J$ h2 [0 o0 bfunction checkform()     
3 a/ f! W7 U5 s2 `" P# k  L# b{
2 R3 u7 d+ V. z0 g. x, A0 y) C  id = document.sform1.id.value;     
& D2 y7 D( S8 q' o- L4 m/ H! G if (id == "")     0 w- ~9 {$ q% f' {
  {     
$ s( \6 L$ F/ y( X8 W  alert("请输入注册名");     
, u: A1 m% _- o  document.sform1.id.focus();     
0 f4 [* M5 E* e- O; o1 `  return false;       v* Z7 @9 K  B# C
  }     $ z5 s4 o* F8 j( K3 M) m
     
% G$ d  B: W% g+ a' v) I# g for (nIndex=0; nIndex<id.length; nIndex++)     + L% _# E1 T3 n% a
  {     1 k- }) Z3 p+ V8 O0 s/ u2 H8 R% q, }
  cCheck = id.charAt(nIndex);     2 E, |$ u7 E" O
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
6 f# H& D/ r' A+ Y) |+ |   {     
' m- s7 d, ~$ G* G1 ^   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     5 C+ e7 x& ~& F: v
   document.sform1.id.focus();     
$ k/ q# ]1 x$ I" G) S# a   return false;     
; w: \' \& ?# J   }     % ~& F1 W) ^$ a, K8 G
  } 0 H9 R, \0 ], Y2 ~: Q, {+ N) O
  chineseid = document.sform1.chineseid.value;     , o* ]6 N- X" X5 s
if (chineseid == "")     
7 {% Y3 W# C. E2 I  {     
4 m4 o- l6 [' ~- m  alert("请输入中文昵称");     
+ }: B) a8 J( H# P: p  document.sform1.chineseid.focus();     6 o- s" o; H9 e7 i+ `9 \
  return false;     
/ e5 b' E. H6 ?1 J  }    3 E  L$ k2 s: [* T9 ]1 h; ?
password = document.sform1.password.value;     - o! L& U. q" p9 Z7 B4 y( \
if (password == "")     
: l9 ^/ T2 [' a" b  {     
+ X7 l- [7 b9 y* g" c) e  alert("请输入登陆密码");     0 ]/ F' T5 w2 U$ h, T, l5 E
  document.sform1.password.focus();       G% \; o2 ~& g
  return false;     
5 P& f9 K; d" H. ?. c  } # D+ X" }7 ?2 a& d. R2 V7 y  e- T
password1 = document.sform1.password1.value;     0 j& B2 b1 a! s+ ~/ u! n9 X8 u
if (password>password1)     5 c2 h3 `! `' h7 y! `8 S
  {, J( x4 n) e" C& K/ a5 j" d/ k0 s
     alert("重复密码与登陆密码不相同");     ( Z' y. W+ U  i: m
  document.sform1.password.focus(); % j  [5 `" X1 _
                                document.sform1.password1.focus();     ) {' j9 L  d' o/ a/ y4 f) @- h
  return false;
- ~) b/ n" F$ s& E2 Q+ J3 K' Y  }  9 }+ D3 L$ W! G3 G
if (password<password1)     
3 P5 f$ p9 F% G# y: y  }+ g$ O  {
; c4 O& ?: ?7 Z( @, {  E     alert("重复密码与登陆密码不相同");     
+ i. c+ N; B$ t! X. q( ]  document.sform1.password.focus(); : ^, `* b  C0 c! ^- w
                                document.sform1.password1.focus();     
* @% z1 {- v- j+ Q  return false;" D" O/ p( G' ^7 ^2 Z
  }
& c  U+ q- n: Z0 y+ F* v if (document.sform1.email.value == "")     
- S- k7 r) s6 ^6 N9 f% I' ]  {     
. m3 ^2 P1 ]; u7 e8 j  alert("请输入您的E-MAIL地址");     
7 B( ~9 a5 s; X* G' T8 t3 t  document.sform1.email.focus();     
" k9 m" D8 |$ I: a/ _, e' J  return false;     
/ o4 [% I2 W3 {  }     ! J# O$ W! _# j. g  _
      7 w4 Z2 V/ \: `! ~* v6 u3 ]% F
email=document.sform1.email.value;      9 w( o* W8 F% ^- _
emailerr=0     & z, {% Y- n9 o2 D
for (i=0; i<email.length; i++)     ! N. s& M) @/ M% U' U5 y  b  q
  {     
' x5 a1 {; H4 V) g9 V  if ((email.charAt(i) == "@") & (email.length > 5))     5 O- u/ O5 n" u1 \9 V# V' p0 Q$ ^
   {     
/ S* d# `4 h. O     emailerr=emailerr+1     
, e6 J( }4 T  E- b) Y   }     . |& S6 ^+ L# B; @6 g. _2 L' ]
  }     9 D; M1 _" |* G5 V% O0 l4 `; \
if (emailerr != 1)     
; A! y6 E! J% c2 v5 ~8 @* ~, T  {     1 M" w5 N2 ~* h. V
  alert("请输入正确的E-MAIL地址");     
# ?' N( ]$ f$ ]+ e: D  document.sform1.email.focus();     
; S$ Q1 T( j' z7 I  return false;     
0 ]& C$ f$ `# C  }           # f& d" N; {' t& e7 I3 r
  " S# ^, n4 ]' T* f3 j- V
if (document.sform1.checkask.value=="")
% w1 r, J) m) f: g  {
0 \3 v- M4 o4 _) d   alert("密码提示问题不能为空");     
/ c( [- B& b% P- y& W: z' u/ e   document.sform1.checkask.focus();     
2 o- M5 B" v( p. G+ |   return false;  7 r' ^4 }3 ]# U: D. A& P6 C
  }
: W: R: V7 h/ R* A if (document.sform1.checkans.value=="")
( ^& P9 y7 p$ V; F- U# @: Z1 ?  { / y, M% D/ K9 _
   alert("您的密码提示问题答案不能为空"); 0 g# }* B" j  i/ f" }8 ]9 S4 m
   document.sform1.checkans.focus();     
( _6 _/ L, s. R; w3 o4 J$ {& G/ \   return false;  
$ J. n. V1 p1 T) V. w  }
% f; p" y4 L7 s0 n% n return true;     
/ F. K% N; V" ^9 e' W" G     
, B$ |7 X- A: G8 o- `  w/ H' K  {} + z- X( ^3 m7 e; p
</script>

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