返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
) ^; h( N8 G9 E1 O' l<script language="javascript">     
7 ]0 K# a9 ^) ^7 {+ wfunction IsDigit(cCheck)     
7 R+ S0 v" e0 K) C8 f9 n# g9 J3 s {     ; W; r- T/ E# J5 J
return (('0'<=cCheck) && (cCheck<='9'));     4 W! S% o- G. Y8 ^
}     3 o4 }7 d/ V5 p) ?9 I1 F7 E8 g3 |
     
7 G& u/ L& S% i: _: c9 K4 kfunction IsAlpha(cCheck)     9 t( P+ W: `* b% `3 n) P$ d
{     
' f! V3 S1 |. `) Q* |- N return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
2 @9 k# U3 E* h% ` }              
5 {/ S7 [. m) c      
1 F0 q$ n- ^  g. g+ i; wfunction IsaNull(cCheck)          . f5 s6 {, ?+ z$ V4 h
{          * h6 ~$ C( [! g& A8 {$ c5 G8 J
return(cCheck != " ")         
% `$ J! z3 @! [6 a1 y9 W }                               - k1 I( {% Q( `8 i& Q- G, t
      ' F2 u2 f4 V6 z, {, I: @: b. U
function checkform()     
# ?; |, i4 `; f3 z{
/ q  A5 H" H* j) E  id = document.sform1.id.value;     $ o, t: x  u( O2 E
if (id == "")     
  H, B: [( o6 J) f7 ~  {     
! \+ Z3 U* o3 m# Q& U  alert("请输入注册名");     
* r; R  A2 V8 N( ]$ A  document.sform1.id.focus();     ( n# I" k  h, X
  return false;     ; t" i- G, \5 w: h
  }     
( m* A  i6 U$ e) \     
' J- `( e* G5 ?& t6 d$ x for (nIndex=0; nIndex<id.length; nIndex++)     ! D. I# |* K% c- F0 l: g3 w
  {     
& g7 x7 c0 |1 T4 v5 s' c$ g  cCheck = id.charAt(nIndex);     
" I: X# N, Z& O  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     % ~1 c+ Y8 S: i( p
   {     
4 R5 a. V8 Z, j9 l$ l$ g   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
2 x3 o) j, E  E1 D1 O   document.sform1.id.focus();     
9 E" d' P, ^( ?( d$ q" Q- F   return false;     
4 x( k5 X. M, _4 x3 j/ E4 k   }     
. ]9 `) y  C: T! W, y  }
: o- Q+ Z0 Z, F5 S$ W# L4 y  chineseid = document.sform1.chineseid.value;     
7 E; s& q/ R" o& a- e0 |: e8 L if (chineseid == "")     ! h5 V+ D/ D& s8 C: N
  {     3 Z7 H  Z5 D" `$ y( i8 L* b
  alert("请输入中文昵称");     
) G. l4 ?: c, w8 X8 v+ C  document.sform1.chineseid.focus();     3 x8 v4 h$ J; G, b1 F  t* F, J' t7 R
  return false;     
- Z# C; T' C, z/ o4 {6 O$ H: q  }   
4 N6 f" S  m* l5 i password = document.sform1.password.value;     & w# m, O3 G$ R& f: N& W1 ]
if (password == "")     & X3 y8 q+ ?7 a: b) u
  {     
# @7 O0 J% d% r- l* ]8 w  alert("请输入登陆密码");     
' l' B: X) T/ ]1 B, p  document.sform1.password.focus();     
# p& V3 D0 a8 X  return false;     
# s" R; ]8 d  s  }
" I" p5 U( j9 O7 b password1 = document.sform1.password1.value;     / P; B$ x- V' M! }. C* ?: u" [) E
if (password>password1)     
, T& Z1 [# `2 f  {. e1 C* F, y4 S, t) O) V( p* T0 g
     alert("重复密码与登陆密码不相同");     
& @6 D! f  @+ }; d8 `4 T) f* w8 }  document.sform1.password.focus(); 2 ~% c: a+ n! ~1 c
                                document.sform1.password1.focus();     
- j' u& e7 i& u$ H; B% _7 D5 j/ f  return false;) W! s5 g% M# ^1 ]' k  L; l
  }  : A2 O+ I' g1 j( C
if (password<password1)     / }. a( V7 X1 R' i
  {
# \. C; b  E1 A. j% S! o     alert("重复密码与登陆密码不相同");     
4 u/ E' n! \  R& Q% r6 I0 m0 C/ X  document.sform1.password.focus();
+ a0 |( d: s: h                                document.sform1.password1.focus();     
$ @  Q' ~( j6 M& T  k4 f* D  return false;& D( {( C$ z& {3 @
  }
" z  H2 }3 O: [8 d if (document.sform1.email.value == "")     
) c* P4 p7 F5 l& T' `$ a# D  {     3 C  J- X" l5 b8 N3 r# f
  alert("请输入您的E-MAIL地址");     ) F# y) c  i- z0 I' N% N) M4 ^
  document.sform1.email.focus();     
2 \% L$ W- V% j  return false;     
0 r! z+ b! s2 o# t  }       }1 j. K+ q0 J; A
      2 a* d; Y  j0 {9 G8 F; w
email=document.sform1.email.value;      " u/ R9 K: K* R
emailerr=0       Z9 x# N: W) ~/ Z$ y
for (i=0; i<email.length; i++)     7 K( V! _  U# ]
  {     0 F/ e" W# [7 a
  if ((email.charAt(i) == "@") & (email.length > 5))     
. h3 s; N) z& G5 Z! D  t  s   {     + B4 X  y5 S# l  I' |
     emailerr=emailerr+1     
0 y) A* @5 S% `   }     
; c1 Q* v# d- z% j+ v( O2 a6 w  }     5 R" N1 A: v) L* g- q( T
if (emailerr != 1)     
2 U! y7 L" P0 q/ L( G8 b$ B/ h  {     ' [% s6 N! X' D/ W
  alert("请输入正确的E-MAIL地址");     9 q( r5 [6 H0 J) Y+ ]+ `% M
  document.sform1.email.focus();     
2 Z- K& X3 a3 ?- f1 ]  return false;     , w2 Q+ v6 F1 X9 C
  }           / b  Y; u) y; N* B# y( W
  
" r+ ?  j' O0 ^# `- V& t if (document.sform1.checkask.value=="") 6 o: z5 m) {  U+ ]6 m: x  R
  {
) R- t, C& M  x6 R( M   alert("密码提示问题不能为空");     * B, a7 A$ I; U8 V% p; i
   document.sform1.checkask.focus();     9 H* V: c9 {" w0 b* O; D5 Y5 _
   return false;  7 J$ S3 f/ L6 y* C
  } , ^; H, g8 w' f: w/ |  N* T6 ?' t
if (document.sform1.checkans.value=="") + P3 Y7 F2 V9 P) r
  { 4 G! k! D3 r6 e( e" c6 o
   alert("您的密码提示问题答案不能为空");
9 K3 l: m  \% ^. X) V! u4 E   document.sform1.checkans.focus();     
0 d2 b8 e2 N3 d, A2 n   return false;  ' s: {5 O) E3 p3 Q) M! C9 ~
  }* h) [% Z' ~; _  T$ _
return true;     
& n5 m- d' Y. j0 N) ]7 q3 x3 }     - B3 E- ?2 J7 ^  F" s% @
}
2 r* s- a& t; z+ e) U$ P</script>

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