返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:+ H3 d* D3 G& X" h4 C( J
<script language="javascript">     4 M! U  d9 h& k8 L) P* b
function IsDigit(cCheck)     - s9 J/ ~1 f  ~0 @- V$ s' G
{     
8 t/ G$ e6 [3 A) A: N: R: ` return (('0'<=cCheck) && (cCheck<='9'));     ( g4 b, P( `6 i# `8 \% @
}     
; U( C; i# o! \  u& O' B     
" f% Z% R5 d5 s! M* d0 D7 jfunction IsAlpha(cCheck)     
: y% j) y- f1 m  N, F1 o# K {     
2 r, u+ D* U# t return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
. G6 A8 p2 H& f% T }              
) B( G* j8 L4 U: \- }5 G% F      
1 _. R9 @4 h" v$ F0 j" T  kfunction IsaNull(cCheck)         
1 H$ z% X' |  a3 p+ E {          6 N; b% L6 m7 [, m1 X$ c
return(cCheck != " ")         . N/ h4 w. S3 s) ^! F
}                              
: l4 k5 D2 C* L; J0 {      , ]4 p- L, C" Z3 Y# G+ W, y
function checkform()     : I) `9 d- Z3 g" Z0 r1 C
{ 6 ]4 b' U* n* p  S
  id = document.sform1.id.value;     ; p8 z/ S$ R- A
if (id == "")     
: ]$ K. ~3 _  {' ~  Q+ Z  {     0 M, r# T( W: `- ^6 R- X
  alert("请输入注册名");     2 `5 d% S! F% y$ u- U
  document.sform1.id.focus();       F' q2 O# y" `# s: b
  return false;     $ `% G" |1 B! N6 [1 u( e
  }     
5 S3 c, y, E# q+ [/ j6 A2 Y& Q  T     + |& k6 v$ _' x
for (nIndex=0; nIndex<id.length; nIndex++)     9 E- b* M$ {$ S5 N/ Z2 l% W
  {     % m- D% R$ K( \, Q8 l+ t+ \4 ]
  cCheck = id.charAt(nIndex);     
; O6 \9 O1 H; ]  L  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
  q+ i/ N0 F  Y   {     * q, w+ L. [0 }, L
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
5 e7 m$ z  f) K1 m   document.sform1.id.focus();     
) _; q/ N2 \$ y* S1 W   return false;     9 p: ]! _+ ^; c/ f- r! C/ Q) d
   }     
1 M% g8 ?$ t( w0 `  }
" A9 H  A- d% D- Y5 {  chineseid = document.sform1.chineseid.value;     3 W! @4 i; Y/ k6 w
if (chineseid == "")       d7 `5 t3 [' k. S6 V& j
  {     
8 C( a  O& E6 K6 g0 D  alert("请输入中文昵称");     
- f9 U# B! y% i2 Y( B  document.sform1.chineseid.focus();     
9 \6 Z  B/ |7 n, x% t  return false;     $ C3 Z% {8 H7 M4 A$ s" e
  }   
# a8 ?7 A3 R$ p password = document.sform1.password.value;     / O: e% c6 O1 x1 f( I' n
if (password == "")     
# {' }: [2 X9 {: f, Z, ~/ n' M- `9 {9 a  {     
/ O; N' v5 |( z$ n  alert("请输入登陆密码");     5 b2 A) F$ ^  a, p5 l
  document.sform1.password.focus();     9 Y5 \- V( x8 H$ v& [
  return false;     0 o" r9 x" y3 X% k9 q) P
  }
; L. b! \# \( r! L password1 = document.sform1.password1.value;     
. e1 R. ]3 D+ s/ i+ i$ Z) N if (password>password1)     
, Q7 y* ]3 u, ]& s+ Q  {" K( r9 E# l  h9 p$ w1 B
     alert("重复密码与登陆密码不相同");     2 z/ ?) ^3 O+ u) h# ~
  document.sform1.password.focus(); 6 h" X0 D6 Z; S& T4 f0 w
                                document.sform1.password1.focus();     5 \, v; ?4 Z' I9 S$ U; e
  return false;; L3 I, F. q( s, U
  }  
  |, C) U  @/ R5 Y) T3 t9 pif (password<password1)     
( Z+ {# h0 l: n3 B7 {  {
+ b, L* S+ e2 }" B     alert("重复密码与登陆密码不相同");     
5 j) P, J& |( f( ^! t  document.sform1.password.focus();
- j1 f% s$ R, t, c5 o! ^8 R" }                                document.sform1.password1.focus();     
/ `+ W' U/ }- S  return false;
" c) s% C* z' Z+ P9 W. @; R  }
! N' q; M9 C, p7 e0 t if (document.sform1.email.value == "")     ! b5 y$ e' ?5 m$ w3 ^" ~
  {     
0 E9 k: s+ g( |" n/ z8 W7 E  alert("请输入您的E-MAIL地址");     ! c6 h; b" n3 {8 w8 T) H
  document.sform1.email.focus();     
6 ~9 E$ d8 o: ?. m7 h; i  return false;     
! ~4 R# @% @, F  _5 S  }     5 E- I3 e8 Q8 J$ E, _- _
      
0 G( G" `9 {+ j1 j7 w) c' _: e email=document.sform1.email.value;      
, ^" N: G5 ]9 k2 Z2 r8 { emailerr=0     . D$ ~- b: [; ?, y8 C+ K0 i
for (i=0; i<email.length; i++)     % ]8 q: u3 _# R4 K( g- ]
  {     
* l3 y9 X) }  P2 @/ }/ H  if ((email.charAt(i) == "@") & (email.length > 5))     
, W* {- q& Y5 m3 T   {     
# Q8 w9 ^$ }. @) d6 J2 s. N     emailerr=emailerr+1     9 c& y8 |/ t9 E
   }     
1 N) ^3 K- n+ `0 }- ]- \  }     1 V  ~' q# d* y: I
if (emailerr != 1)     8 n$ E; e* s  C7 D# W* Y
  {     
2 R  }$ }; \8 A" {  K  alert("请输入正确的E-MAIL地址");     
- V9 b$ K! m$ p3 _$ @  document.sform1.email.focus();     
- K, ]2 o, I+ V) ]  return false;     
3 M% J* c4 A& X  }           
# n7 J( C8 `& A: s  " n4 ?% D. t) \+ A* \
if (document.sform1.checkask.value=="")
) ?. I5 g. t4 f3 |0 C* C0 p  {
( C# W, N8 t) q( A   alert("密码提示问题不能为空");     , N% [, O1 l9 g1 q- K
   document.sform1.checkask.focus();     # Z- l0 {  q5 q. ], j
   return false;  
$ ]& l: D1 n1 n' c: m. x! D0 }% }  }
& ^8 `/ x3 t3 k3 q) X5 }! P4 w6 x if (document.sform1.checkans.value=="") : Y8 G5 w; z+ f! @) H
  {
4 K, Q  F7 v# I  E' d5 V   alert("您的密码提示问题答案不能为空"); ; n6 R1 C: O9 l  ?
   document.sform1.checkans.focus();     
; ^6 ]: z2 E; v  [. m3 \   return false;  
5 q( `, ~% T* j4 C) J$ W  }
" e1 O2 L- P9 C( ?3 I return true;     
1 ?2 A, Q8 V% N% E3 y     
6 o2 o! _4 h  K9 I9 C4 F}
9 v+ e: F& Z+ q, ?7 w</script>

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