返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:% F/ Y' ~# q  `7 }1 X
<script language="javascript">     
6 f+ t" H. u% ^; cfunction IsDigit(cCheck)     8 M) @- L2 u' {4 ~' }$ a
{     
" q6 K$ O3 x7 I) n# {8 y return (('0'<=cCheck) && (cCheck<='9'));     0 M. l: f' [; n. p. e
}     
) f" ^) g0 g$ ?; v3 @     
5 ?. b1 V. ^6 B! }function IsAlpha(cCheck)     0 e: x3 I0 z- w; S  u6 e2 D! S# {
{     
0 r0 W: i+ ]4 _7 D& H/ U( v/ i; a return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     & j( ?7 x3 |/ |
}              ( @" [( m% P4 T
      
8 z/ R* f! E0 y$ G3 Pfunction IsaNull(cCheck)         
- h2 o( I3 y+ ^; m2 o+ _ {          + M. O' s, H7 t9 B/ s, X$ {0 D
return(cCheck != " ")         
3 I/ N# |6 d- S) h# @$ T0 C }                              
" K" \1 s4 o) ?: C* H7 ~+ ?      ! C, C& v; z2 q5 [/ ~
function checkform()     
# L. s" X0 m/ h8 @# ]  P{ * L  q& A/ s8 N/ L- ^) T
  id = document.sform1.id.value;     : V  n5 Z+ |4 I# \( e4 b* O
if (id == "")     4 q3 Z% ^3 O* F5 R
  {     4 d0 M% k; j9 {* g- h
  alert("请输入注册名");     
' @( q8 T; O3 s2 n! q4 k1 R  document.sform1.id.focus();     ' m- o& o8 P" R
  return false;     
% L( L* z: V2 H% h  }     % k3 V6 e1 w4 a8 Q
     
' l6 {% T+ x* _! L for (nIndex=0; nIndex<id.length; nIndex++)     2 w9 _9 t! T0 S8 ^0 K) ~3 H
  {     7 F  l* H+ K, D0 B
  cCheck = id.charAt(nIndex);     ; l5 T  L, ]- w" Y9 o& b* E
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
- `# j! j; V3 r4 q   {     ; o2 |- S1 y, J2 s% d
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     5 s; }1 c; g& b  @- C. m" g
   document.sform1.id.focus();     
# ~8 y% V$ Y4 ?( w+ \2 f  x& O   return false;     
( C; D+ y. _% ^9 J   }     ; {" Y/ [9 m$ g
  }
# Q! V* m- p& C& s  chineseid = document.sform1.chineseid.value;     5 u7 G! N: A: f$ j) |
if (chineseid == "")     : M; d$ ~6 s2 g( T7 ]
  {     
6 c2 \+ Q; G# I5 C& `2 m* K/ W  alert("请输入中文昵称");     * L' r* T1 f% E: B
  document.sform1.chineseid.focus();     4 R, k8 N3 J! ]7 a" c* W! k
  return false;     " V; v6 p) M+ Q+ I& g! }. G9 g) l
  }   
4 Q6 t, |! g2 q& W password = document.sform1.password.value;     ' W& j3 J3 _& z& Y
if (password == "")     & b; r5 I2 Q, N. H, [5 D
  {     6 m& O- ?1 C! y4 \0 ^. b! P
  alert("请输入登陆密码");     
8 k$ o) S& q) U. i  document.sform1.password.focus();     3 |7 D# R! q8 b. F& E$ w
  return false;     5 \" F. c" }( L2 @4 m
  } 3 T5 X, ^, S1 Z5 R4 k+ X
password1 = document.sform1.password1.value;     
* t( ]- |5 h# |# Q' [- @* Y- E if (password>password1)     1 W' f/ S6 f; @$ J; u2 E- c+ z
  {
2 g* P2 Z7 l) Q8 j* k     alert("重复密码与登陆密码不相同");     3 w# _$ v- K! D5 c6 |
  document.sform1.password.focus(); , q% ?/ F& s% f9 }" _1 m) t3 b
                                document.sform1.password1.focus();     
$ d3 A' `7 T$ k) |' l- y- S$ j' \  return false;
3 S* N/ V, Q: I0 w3 n' Z5 i8 k  }  : h8 P7 G4 U8 [  w9 Y1 \
if (password<password1)     
* c! {) K9 {# b$ Q# z, `  {' |) \- U- N( ^% y6 }6 W. i8 ]
     alert("重复密码与登陆密码不相同");     9 o+ k0 j% W) j0 }3 E
  document.sform1.password.focus(); ( o1 G( N5 U- S- v! I- j' N
                                document.sform1.password1.focus();     
# M, i7 \. f  S9 P( m  return false;
& f6 Q% k7 Y& S) @& _0 i  } 0 C" w5 |* M" \3 y; X+ }3 e
if (document.sform1.email.value == "")     / X* R( d; P" [
  {     
8 c7 i7 K" S& k" \7 J+ Q2 R" }  alert("请输入您的E-MAIL地址");     7 K( V/ l0 |$ v# u# O
  document.sform1.email.focus();     
: b; i2 }9 I9 V. }  return false;     4 |/ `& D0 a, ?; y' B/ U& o
  }     
/ Q8 @5 V1 [0 m' A      , h9 i& @4 R1 L7 T
email=document.sform1.email.value;      # X9 s  ~9 h! f. Z. J5 \4 [
emailerr=0     
* J: V+ k. _  d, L# ~5 R for (i=0; i<email.length; i++)     
0 ]" Z# w8 ?0 V8 R- Z0 v, L  {     
$ q( }& Y) x# K  if ((email.charAt(i) == "@") & (email.length > 5))     + T8 R- V" F3 D
   {     
$ A/ w+ a& H& g' I     emailerr=emailerr+1       i; [5 z1 e" f3 U
   }     
1 p9 c4 T; h) t3 B  }     
- M5 E8 D* W# {: ^: _8 M8 g) _! G if (emailerr != 1)     
9 F* ?7 q+ g: k, K* f) C. ?  {     
) E% x0 Z; g, i9 e  J  alert("请输入正确的E-MAIL地址");     
9 A1 B6 x5 a% K  document.sform1.email.focus();     
9 s0 _$ f% R! M4 r. A  return false;     ( \$ j/ p& I4 K( z0 |$ r) E+ K$ Z- x2 K
  }           ! t. n* p8 v4 m- l# i% p4 D
  
- h  A0 h+ P! v3 z if (document.sform1.checkask.value=="")
' W5 I* ^$ @8 I7 F  v5 a  {
* m& ~6 O. n, A* e! A   alert("密码提示问题不能为空");     
8 C& Y/ z% k% x" W' A4 ~   document.sform1.checkask.focus();     & R' E) L( U6 w
   return false;  
% h8 E5 G: P& u8 C6 |+ ]  }
0 L  d$ C( v( y) y if (document.sform1.checkans.value=="") ! k! R/ o3 ~. Q+ `5 O& e
  { 5 S4 f) _3 Q. @6 X! f  x4 H5 q
   alert("您的密码提示问题答案不能为空"); 7 X6 p7 B8 R+ }8 s
   document.sform1.checkans.focus();     . W) O% e2 W8 k
   return false;  
0 f: {5 @* P' T0 \0 l0 |  }
2 }- n+ q! O1 X9 z7 ]/ v return true;     
: g8 s7 v% p+ J$ e) d7 F/ |     1 y9 K& H8 `% {0 k! s
} / I, a. {% ~+ f% |" A" C" _
</script>

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