返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:% W1 B  }7 c; G- p6 v1 D
<script language="javascript">     " Y1 ^! n8 I9 l: }6 y' ^
function IsDigit(cCheck)     % d! t6 `$ `. T; a, Q! V+ K9 K7 E: d, G
{     0 p0 E( d  L! ?- @0 F1 p8 Y* U2 b4 n
return (('0'<=cCheck) && (cCheck<='9'));     ) V* v9 \2 n1 S  R& x
}     2 x* o' V' s8 i+ y5 h" r3 a
     7 O, k* z- ]+ {) d5 A  u, Y( ^- y
function IsAlpha(cCheck)     
: ^6 M+ V3 X3 {5 Z" r {     5 q1 [7 l+ p" d$ e0 M' ^
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
3 K9 |2 o% t7 {% b' N }              
9 ]) ~; C/ M. z/ y# h      
2 I( [6 i4 {! Zfunction IsaNull(cCheck)          6 Z- @3 s! O  f
{          1 n8 `; O# S0 n$ o6 ^, `5 t& t
return(cCheck != " ")         
+ t: H0 p6 U& T# o) [ }                               4 \; J( h8 p8 R& v$ P9 C: M  Q
      
& O/ Q4 R( `/ l# Z. `  ufunction checkform()     
& H0 B/ {) t4 `% y$ X{ * f. ^, ?, Q! S( o5 [
  id = document.sform1.id.value;     
6 i  Z$ G* k+ C  Y if (id == "")     5 H! N6 L* d2 g4 L4 ?0 L( L
  {     
9 F7 |6 z$ c! E1 n  alert("请输入注册名");     
* z, C! U* W0 q# |9 R1 Y  x3 k7 w  document.sform1.id.focus();     6 `# s4 `) K4 P% T: h
  return false;     
/ m1 B! }, d# U  }     
0 l* V4 g  x( f9 N0 I* R     
# `( ]1 Q/ m& g; l9 q# R, Y6 k for (nIndex=0; nIndex<id.length; nIndex++)     1 l& I4 z) b" o; [+ [
  {     
2 m" }8 O, D2 Q  cCheck = id.charAt(nIndex);     
" I2 C5 ?* Z) O: \( F; r- n+ X  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
# x! `4 _$ z" t1 E9 r   {     
/ i8 E5 j. t3 O  b: U/ N$ E   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     . L, p( s! y6 I# U
   document.sform1.id.focus();     
$ j, p( T0 b6 E  l% Q4 k2 U   return false;     
" \4 M! T! s/ K, y   }     , _! z( @% y: @+ w' C) g4 @4 {
  } ! b8 x* g9 t4 k) U% Z+ N
  chineseid = document.sform1.chineseid.value;       i% |5 M& W' o& d* P. T: k
if (chineseid == "")     
' m# V" T* [, Y% `, g, G( i  {     / m% b; X5 n5 p+ @9 l6 C$ E
  alert("请输入中文昵称");     1 ~& m% G/ y& E* Z* ^; y5 @: z
  document.sform1.chineseid.focus();     1 Y; \. w6 z7 y
  return false;     
7 u+ t( f) a  `6 |! C* V$ k  }    0 D+ X, u; Q3 b' b( v- s
password = document.sform1.password.value;     
4 ?( F; j7 D- i/ n- e( I" q/ X if (password == "")     6 ^: E9 h* M3 C4 N
  {     : O, U! Q5 A# ]) J
  alert("请输入登陆密码");     
  x. \( c6 i$ Q' N' G) [  document.sform1.password.focus();     6 X- c' z0 y+ v. o; Z2 H8 E& T
  return false;     
; ^: J8 x: f8 y. [6 ^  r8 s  }
" v; O& O  J7 ?" z/ p password1 = document.sform1.password1.value;     5 f" q6 f$ Y- l7 O7 G: J
if (password>password1)     
+ A6 U1 ]$ L) x5 V' e: O- p  {- }. w( ]* ~& H2 G
     alert("重复密码与登陆密码不相同");     + I, K6 R! }! A% e
  document.sform1.password.focus(); + [6 d7 Y/ i9 ^# v
                                document.sform1.password1.focus();     # y1 F7 ?1 o$ N- f6 m
  return false;
& y- I7 d# h8 N& U0 o! ]* y  }  - o6 e0 i/ G2 @# G) T
if (password<password1)     . S. L+ X$ H! S( o
  {) t. ~$ d) y! Y7 l0 H
     alert("重复密码与登陆密码不相同");     
' }# f/ \3 Y/ a! @, b  document.sform1.password.focus(); ; S' [1 S$ Z* I2 \: V% }# l- V
                                document.sform1.password1.focus();     ! Y1 i2 r! r( U; i1 A5 h
  return false;  o) X- i+ l. E. c. c
  } $ j& i( d# m; f" t8 e2 s
if (document.sform1.email.value == "")     
# p- n4 v0 ]9 f$ t0 m" v  {     - J+ W2 W& N" H- H9 X' g- N& q) k8 h4 I
  alert("请输入您的E-MAIL地址");     
+ Q9 @- L( O# V) K7 Y  document.sform1.email.focus();     ) ?3 W+ t' |" c0 S3 Q" P: c
  return false;     1 P/ v$ c$ @% x4 u7 h& C$ j
  }     
3 L( @" v  T- ]      - P- |3 A' d! k; k2 J2 b
email=document.sform1.email.value;      
" y, Q) h  l/ M4 {7 U; Y' n, n emailerr=0     
8 F7 V1 p0 t# e6 h+ D for (i=0; i<email.length; i++)       k9 d0 h% p; i
  {     
3 F% W  `* V' w; b0 H4 i! |( A! D  if ((email.charAt(i) == "@") & (email.length > 5))     ) L# u0 j8 k- T* ?
   {     
: b, Y! t2 E& O9 B$ Z& H     emailerr=emailerr+1     
' f+ n5 M' m" b8 z   }     
  I: `3 I$ i5 |+ k' F  }     
7 w# P9 C& T; f4 s; ^7 ?5 ^0 i if (emailerr != 1)     - j5 b% [  I- {) ?& L6 R1 _: S8 k
  {     ; _! V! g) N8 [. O" {- x/ j6 G
  alert("请输入正确的E-MAIL地址");     
8 t, Z: c  i$ o2 k7 D; Y- S& @  document.sform1.email.focus();     
' `) {% G) L" d5 n! ]' P) g  return false;     
/ {% Z* a4 G8 C/ ]  }           
0 O6 u+ b# S, e+ R, \& O3 {- Z  
& A1 w. \( b$ _: p7 t5 e) z' ] if (document.sform1.checkask.value=="") , @6 \0 v5 j" c- e+ {) N
  { , Q" Y) r5 b  r" l( s
   alert("密码提示问题不能为空");     
2 R& w% K' k) @- [   document.sform1.checkask.focus();     " c4 J# X0 P5 w
   return false;  . v+ A: I" u: [: c1 l) I$ b* O
  } * j  C' x+ Q9 N8 E7 \4 E% S
if (document.sform1.checkans.value=="") 0 K0 A/ F( Z* L0 |, Z5 I/ s
  { 0 h( S$ D2 w/ @/ h+ i
   alert("您的密码提示问题答案不能为空");
3 w5 N8 C. W; c7 @" [   document.sform1.checkans.focus();     ! `# B$ J" w8 j+ l8 Y% j
   return false;  
" b) W6 f' ?. B: p1 {; C  }
- v+ m1 a) t- t' q* {" m return true;     + Q' T0 `/ H; t' @% b
     9 G$ I/ O' A/ [# B. H/ U
}
$ N" C" \4 T4 P: ~</script>

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