返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:: t& U5 P0 o/ e
<script language="javascript">     ' V( ?- M% D$ g- b
function IsDigit(cCheck)     
: d, \* [2 h* {0 f  n  U1 I5 {) y {     
; L4 r; s; t( N. r# x return (('0'<=cCheck) && (cCheck<='9'));     / c6 I7 z% K. j5 h8 m; E. B
}     / H, V8 ~9 H7 w; j: d  Y  ?6 f
     " S+ |# I3 W7 _$ B& o
function IsAlpha(cCheck)     
# J. u' Z9 t* ~7 t( t {     
: a7 z7 {- t. K- w2 L return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ) Y5 ~  g0 D. w5 n: ]# y5 Q- a
}              ( l, [) u* v3 x
      
: J+ `, |# I$ H7 o6 P) tfunction IsaNull(cCheck)          ) S0 |$ t' N2 i% F
{          ! I3 B5 K3 I# `# O6 F$ i' A. G
return(cCheck != " ")         
8 w) D* M6 P# H; z3 g' Q& ? }                              
% t2 y) U3 s; j3 t' I      
% W9 _6 \4 T2 _2 p* lfunction checkform()     - x% E9 M& ^$ L7 u6 s
{
9 d  ]6 L& T; p  B8 Y8 z6 E  id = document.sform1.id.value;     ) G1 V) M& b) d" x: D$ U
if (id == "")     % q- A+ I, V0 _9 h
  {     
$ O- G) _0 N0 C7 ]% g, n  alert("请输入注册名");     ! [- C6 u! z5 D
  document.sform1.id.focus();     
& ~* n: v# M- T- T  return false;     
2 I9 G3 c% M6 }  X& T: l6 B1 `8 @  }     
; m2 q$ S! x0 a6 ~; u6 o     
$ f  }! T2 C  \ for (nIndex=0; nIndex<id.length; nIndex++)     / W0 z& @1 c/ Y2 R- j6 {
  {     
2 e+ w' W. l5 z; T  cCheck = id.charAt(nIndex);     
, s, S& g& e4 H2 x6 A& N- d: W% }  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
0 R) T7 _( T# u" w4 a   {     
  a. W* k" c+ G$ Z- l6 k! x5 u8 K   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ' M$ k1 M7 L. W' D
   document.sform1.id.focus();     ! m/ |: C7 e4 Y/ b! h, p' d
   return false;     / ?8 O5 J- @% o. O5 I4 s
   }     
. g! {+ j* n" b2 S" M; M  }   {% r! A1 `  H
  chineseid = document.sform1.chineseid.value;     ) [: H% A( O1 D6 J( a2 k
if (chineseid == "")     
, [$ p7 w; t6 `+ [' t  {     
% P% B4 r' v" v. d2 T0 y* F5 K3 J  alert("请输入中文昵称");     ( `! \0 I9 t) z' d8 F. `& [7 m9 |$ S, M
  document.sform1.chineseid.focus();     ' E: t8 R+ f, e
  return false;     
) P" T0 ?. o1 G+ D: V  }    ! j% E! V; h' g1 w9 O8 w  J
password = document.sform1.password.value;     3 f# f# \7 `9 L2 b: v$ b
if (password == "")     
# P4 ]. @$ `" \$ N1 N8 G  {     
; ~- p( P* I/ ^9 }! L: K  alert("请输入登陆密码");     
- ~0 V( c" i/ C7 Y  t( w1 u  document.sform1.password.focus();     2 j( S% u1 L' q: n
  return false;     
" ]& ~: {' d, u" b  } ( n4 s  G  O3 b
password1 = document.sform1.password1.value;     % d2 ?/ o; I  o$ R" J* B
if (password>password1)     : X# @8 ?3 h4 r+ d
  {
1 F1 e* {+ D6 b3 W, |/ w     alert("重复密码与登陆密码不相同");     1 \' I: S, l1 }% Q, I
  document.sform1.password.focus();
: b9 x' p- U" s, [' H3 ?                                document.sform1.password1.focus();     
8 y+ f# Q: f# E+ y) |) V  return false;/ h- {3 V3 E% H" C
  }  - R7 P( ^% [9 g- r* K# B
if (password<password1)     " x# {' R0 e- `" `0 q, f
  {3 P& Z8 p' b! x& t" P, _; P
     alert("重复密码与登陆密码不相同");     
; x( c( @9 s. k6 `5 ]  document.sform1.password.focus();
# O4 P9 A2 A! ^) h                                document.sform1.password1.focus();     
  r) E% i* w8 p' Y  return false;
( B  }! G+ ?6 c0 U2 b" R: M# X  }
( x2 ^9 t6 |* O% q& ^" s if (document.sform1.email.value == "")     9 @- S* ?, ~  x1 D6 R  ~  R
  {     # a# g: Q7 i8 T; S: s4 j
  alert("请输入您的E-MAIL地址");     
" e& P% V+ x# C3 q  document.sform1.email.focus();     6 K* L5 [+ h) G- F5 h( d
  return false;     
' k; A0 E, C- O8 t* L( p7 E3 f9 m: u  }     
4 o$ }$ P6 O- k  _1 H      4 S- l0 e6 i( R% ~/ `5 t
email=document.sform1.email.value;      + t. `' q0 ]: d/ B, x- ^
emailerr=0     ! E+ f7 B# }3 S8 `! M
for (i=0; i<email.length; i++)       I$ I/ V; R7 D' p+ q, m1 o  o
  {       V9 ?* m+ o. X' d* [
  if ((email.charAt(i) == "@") & (email.length > 5))     
) B# K. ^+ N! {9 X+ e! d; B/ W   {     ! N4 C, z9 `- _1 L5 q: F- `- }! B
     emailerr=emailerr+1     , ?6 N' [1 {" \$ t! s) t, q  S" y: E
   }     8 E: c9 O( n8 l, W+ ?6 ~* j$ v3 Q
  }     7 \% w9 M3 j* D7 h  U- H
if (emailerr != 1)     
! ?- J3 [) o: D5 V' p7 l  {     4 H$ [9 j# u3 a% Y' z. s, a
  alert("请输入正确的E-MAIL地址");     
! Y  R+ w) e) s# K  document.sform1.email.focus();     ( L$ I4 ^* {* y
  return false;     8 h6 m2 u% C1 U
  }           
$ p/ m9 u! j/ F& O6 h  : v2 F& T7 S! I1 X1 Q, z  [
if (document.sform1.checkask.value=="")
' f& `% \" ^1 E$ d( n3 w  {
: r9 d" [6 |/ O/ w9 k   alert("密码提示问题不能为空");       T- W6 @) j$ @5 f, o+ g. g
   document.sform1.checkask.focus();     
; l( g9 o5 h% Q! P   return false;  ; f' \) y* X0 g( u3 \) }
  }
3 G6 t; H. M+ ]! O$ U2 J! z# o if (document.sform1.checkans.value=="")
( R0 k' T& \5 \. P  {
5 @, x/ O: {+ b2 Y- S  N2 Z   alert("您的密码提示问题答案不能为空"); 8 Q/ r6 u( X3 B' \$ {- j
   document.sform1.checkans.focus();     
5 @$ U4 {8 h2 q   return false;  : ]2 R$ L  _+ `' U. \# D% O, A, P
  }
% ?7 N+ t2 U4 t, Q  ]* F return true;     & R3 z! M, j$ s* A0 M$ |5 f
       }* C% w/ P, C3 m0 j
} 8 L3 D7 w4 u3 A( w  N8 I9 E$ \6 m
</script>

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