返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
8 L5 ^! H3 p. u9 B<script language="javascript">     
( Z: E0 J# P* mfunction IsDigit(cCheck)     # ]# X# p; f9 F# m: [/ D3 P
{     
) e# g; `- u& f. c+ k5 b# _ return (('0'<=cCheck) && (cCheck<='9'));     
* e6 x5 ]- l) m2 j8 I! K }     
/ U6 O, w$ r  `7 q% ]( _! ]     ' K! F6 _/ A% C& ?& d& g& J9 ^
function IsAlpha(cCheck)     
- {5 e9 w! G5 C% g6 D6 h4 h {     
. M6 A+ \0 k6 i' u1 n" `: k return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ; r# G6 h: B4 {- B
}              
8 S1 u$ [! z! {) i+ {8 `5 Q      
  M4 U1 ?& Y; f' Mfunction IsaNull(cCheck)         
+ \3 U3 q3 \. y6 u) M5 C {         
) }. R+ |4 e: i- F8 o& w' d return(cCheck != " ")         . \- `: |, `0 n3 g, e7 j! c
}                               7 _; e- w9 Y- ]6 T
      + k" `# q1 y' F
function checkform()     9 ?) Z4 ?, G! ~
{ . \/ W% {8 p9 U: ~3 _$ z
  id = document.sform1.id.value;     & e( y* g) J& U% }% E, {. @
if (id == "")     # F1 z, O5 u2 H1 u7 x) X1 g. s' c
  {     7 l( C# O8 W% M3 R3 ]. B
  alert("请输入注册名");     ( H4 \9 Z- e  Q9 A9 S
  document.sform1.id.focus();       K  j# S$ m7 X( h$ u9 M- ?: J6 L
  return false;     
4 Z! A9 {6 E+ \  _% _$ G  }     9 Y% L  s& H5 U; ]
     ' e4 i5 f$ b7 ^
for (nIndex=0; nIndex<id.length; nIndex++)     
+ |+ ]7 |: Z& ~; x  {     # V8 r! t2 I4 K0 w& O  Z
  cCheck = id.charAt(nIndex);     
8 u5 i* ]& d& p8 i$ s- [8 x; ~1 k  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
( K. N/ B" p& h/ e4 M   {     
, i  d' t0 W$ ~+ K  v- Y   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
6 L" G8 {- o1 H1 O+ O  u& C% O' {   document.sform1.id.focus();     7 Y" L9 p+ G7 a, e
   return false;     
1 B* Y1 C: f# z' T! I; U   }     
- C' n# {  B& q! v" ~* }  } & a$ a! t' `+ f0 c/ j+ Z" q
  chineseid = document.sform1.chineseid.value;     4 C& `. H5 w# H
if (chineseid == "")     ) v. y* ?: S1 \7 M( Y: l7 U: H* P
  {     + @( a7 r4 e' u8 ^+ e! `  l
  alert("请输入中文昵称");     
& `% x6 u# B8 d9 J* P9 J" j  document.sform1.chineseid.focus();     
% l  W/ U: g2 P, }4 J& I! p: j  return false;     
9 p+ W  K2 W" r% b  b: p  g  }    2 V) q  I9 D& [2 K
password = document.sform1.password.value;     6 O- G  \5 j0 q% E9 F) _
if (password == "")     ( a3 i1 X/ }; P' a* ^% a$ [$ W
  {     
+ G# M- |1 c# Z+ h6 C  alert("请输入登陆密码");     
7 }9 J5 A0 U5 j  document.sform1.password.focus();     
$ m+ ~0 B, P5 j3 C  return false;     2 `- n- q3 l/ N% y
  }
8 z' x9 ~) O  l6 y password1 = document.sform1.password1.value;     
: w0 v$ P! a2 _ if (password>password1)     ! Z  E0 {; [- H  O2 k1 V9 v- U3 g# a8 [
  {
3 t0 E8 C- [/ Q  n     alert("重复密码与登陆密码不相同");     ; h5 d9 X6 t5 Z
  document.sform1.password.focus();
% s1 ?2 s  P* I) n                                document.sform1.password1.focus();     
$ K2 B1 \) K' }! C- s' N  return false;
' X0 O' p- d3 a; T5 A6 k" Q) [  }  
. W& s) D3 d. Z/ d8 [- ^/ H4 Rif (password<password1)     
8 \  O/ R7 V" [  {6 S. s1 I8 K0 C$ t' S! j3 _1 B
     alert("重复密码与登陆密码不相同");     ) z3 _( L  Q/ R0 `! k, e* X! y
  document.sform1.password.focus();
1 J7 a4 m8 f* f& h$ s2 E* W. U- c6 R                                document.sform1.password1.focus();     
7 `4 P% M5 s5 P. k: w  return false;7 N2 _' {* ~. v8 G  M) R& M
  } ! f$ F2 U" c$ u
if (document.sform1.email.value == "")     
' v5 |7 [/ C' R6 U/ `, C: M  {     
! r# Y# `' h- V  l# x  alert("请输入您的E-MAIL地址");     
. r5 n% l% Y% A0 ]+ k+ r! V- b. g  document.sform1.email.focus();     3 |+ _& F. G* f6 x# x/ D
  return false;     2 h! F, ~5 H% B# R7 @
  }     ) b* I: q3 H7 g
      : V' O2 P1 x: G. n+ c4 U7 Z) ]
email=document.sform1.email.value;      5 H5 E/ B% O3 F1 J3 K( D: P8 n
emailerr=0     
6 y; j7 U  Y, U- B; L* u for (i=0; i<email.length; i++)     ! Y, O" ]& V8 b. K" k. t2 z
  {     4 a- i1 q1 {/ K, u% ~
  if ((email.charAt(i) == "@") & (email.length > 5))     
8 L8 O" Y8 L9 q/ l   {     
7 g* L  H5 h% Y9 O     emailerr=emailerr+1     3 F, z7 {0 ^* B
   }     
/ w+ A3 Y4 @. a; @! p  }     4 [% s3 l0 d# n' V
if (emailerr != 1)     
% W9 J3 B4 C1 M* [+ C6 c  {     
/ @8 o4 P* q  u# {1 b  alert("请输入正确的E-MAIL地址");     
  }, a! s% U& g& s" x  document.sform1.email.focus();     
% V- r7 a! ^9 X% U* n4 b$ u  return false;     7 E( X) @7 U% Q
  }           0 p% I. K5 W( W, T" h- m# s$ e
  ) J/ P! ?9 b, W% a2 N( W, o8 Q+ w
if (document.sform1.checkask.value=="") ! \3 Y& y1 Q; P8 _+ @
  {
, ?) ^( y7 @* M! `3 m) v  {   alert("密码提示问题不能为空");     
/ Z' m, U. B  {   document.sform1.checkask.focus();     
$ r) q* A7 l) c) s. G6 W   return false;  7 z) {4 \7 ~* \7 K' q9 I2 d0 f5 c
  }
) b' v& l, ?; W$ t1 y if (document.sform1.checkans.value=="") ! r8 h1 c' V7 T* a
  { # }, R+ m' I4 _; H9 e' s2 b$ d
   alert("您的密码提示问题答案不能为空"); ! }7 c8 ?; w) x; [& T
   document.sform1.checkans.focus();     7 A+ K' P+ A" W! T+ U9 {9 o: v, W4 o" f
   return false;  & p' Y1 s% }' K  U
  }
0 v3 I  U% X2 l return true;     & k: Y8 {- W4 w$ A, F
     8 w6 B, {& X: |9 Q
} 7 I. j1 v) c1 g, S" r
</script>

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