返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:) X. M( ~* N, ?. E* v/ M$ P6 g
<script language="javascript">     
( C+ j, ?" l* y& I! u0 d. Jfunction IsDigit(cCheck)     3 N, F: R+ b  C( \
{     
2 y( }- ~, T0 J# U2 | return (('0'<=cCheck) && (cCheck<='9'));     9 d/ E7 Z/ @! h8 Y: w+ O+ f
}     
/ R. r+ s% J! Y7 k4 Y% ]: Q4 c     7 Y1 t+ Z2 B3 _8 h6 \
function IsAlpha(cCheck)     . r* t* h7 {- G5 I+ X' X# X9 q
{     
9 h0 p$ ]* L% I5 h7 t8 |8 P: O return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
  g: k" R; _' E$ m( O$ D/ K- f6 L# e- f }              ) x$ Q- D0 y, U7 v* p  `
      
$ I9 ]. Z" y/ c' x9 `, Zfunction IsaNull(cCheck)          ( U9 b8 W, X  L7 R) [
{            j6 A( r' e/ E# q. V. [
return(cCheck != " ")         
5 k+ K2 C) X1 ^: n$ } }                               " K  ?7 A: s: I
      : C7 p8 W( k/ g5 n5 O5 [9 I( \- _
function checkform()     
  D; i7 N+ j6 O7 b/ h9 f6 A; e- K{ $ P5 S, g! n7 ?$ R
  id = document.sform1.id.value;     
0 }0 [, S1 R& W if (id == "")       Z; V; d1 I  b0 G
  {     % T/ i+ K8 }% l6 S
  alert("请输入注册名");     ! I3 Z. n+ i4 x0 j
  document.sform1.id.focus();     * t, |  T3 P2 V
  return false;     & H8 K( o8 o* `5 f+ E. `- [, c
  }     
; B/ l) ~( h* i0 w' p     
2 U5 }2 E  y$ n) h for (nIndex=0; nIndex<id.length; nIndex++)     : G, [: E* G2 Z5 L; Y, R! u
  {     
: F2 `) w$ j2 r6 V# t) z1 H  cCheck = id.charAt(nIndex);     
3 L. R) `8 J; ~7 S  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ' a5 c( y( h' U* J  k
   {     0 e) n/ E; w9 q( q
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ! ]7 O# O: j7 }8 M
   document.sform1.id.focus();     
8 n7 B; t$ {" j: `8 R$ Q4 y, c   return false;     
- h# X$ s+ ?4 G& n& e) R   }     
- f% J. N6 q% n" L+ [* p  } 0 k' E8 I  r* n  O4 I: ]) T- d
  chineseid = document.sform1.chineseid.value;     ; D; r( @$ d, Q2 w4 C" z5 G/ {7 M
if (chineseid == "")     / U4 \; `7 ?9 }1 H2 M
  {     - n+ C% \$ z% R5 E! Z
  alert("请输入中文昵称");     
8 _4 |0 M% s4 l4 s  document.sform1.chineseid.focus();     
5 n2 G0 v  H4 f, D  L# i  return false;     + g. u& G! n4 v) D" E) i! V; e
  }   
7 m& U2 h1 z6 L7 K password = document.sform1.password.value;     
4 L3 e% f% m' F: S: `. L7 a( ]$ r if (password == "")     8 ~7 m+ t. u6 {1 `% O
  {     
0 b% [! w% M3 F# u3 g" j9 E5 K  alert("请输入登陆密码");     ) y# i/ ]* s" F% e7 p3 T. n
  document.sform1.password.focus();     1 r# `/ S5 Z# L( J9 O$ E
  return false;     2 @2 l# J+ S! Y1 g, O$ ~
  } $ V5 _: Y' K1 M+ O0 t+ R- E
password1 = document.sform1.password1.value;     2 T5 P( O8 s! T& F/ P/ k  T# Z
if (password>password1)     4 [: [8 {: X4 X6 J+ \% A4 J
  {
1 _3 F) m* D& M$ [/ T& p     alert("重复密码与登陆密码不相同");     
: g6 q; R3 N1 t- g  M  document.sform1.password.focus(); . o& a4 _# E/ z9 L2 ^9 j
                                document.sform1.password1.focus();     6 ^: z: P0 [- O; P4 t0 i/ j6 S
  return false;
$ U6 U. Z1 \7 w  M, K5 W* g  }  
( F1 z5 D# S$ E+ |if (password<password1)     - q9 u! N$ U, ^
  {
2 P- n' \9 N+ j% z5 h     alert("重复密码与登陆密码不相同");     
* N7 z& B5 W& ?' ^7 j( g' s# n3 V* K  document.sform1.password.focus(); 4 j8 W* x' ^" ^* @0 J
                                document.sform1.password1.focus();     " A* C5 g( K+ L' S$ i: R9 I' A$ x
  return false;
5 K5 e# u% f6 t  ]4 M( D  } 9 d+ R2 U9 d! J3 v2 M
if (document.sform1.email.value == "")     " m5 T. Y1 f2 P' Y0 |
  {     " t; i5 F: j4 b
  alert("请输入您的E-MAIL地址");     4 d3 v+ p! h/ t: G8 ]$ f
  document.sform1.email.focus();     7 l. y* k8 L' q. ^9 {/ E0 _
  return false;     5 _9 y5 t; F4 c4 f, a9 x! V
  }     
. o/ \0 Q- |/ y3 @      
4 w6 }4 i! n4 m& e! p3 W3 ]& R5 q email=document.sform1.email.value;      
) w' F3 `( R' c8 p# D0 o# I1 _ emailerr=0     0 z; D! s7 w+ H2 c! H9 p- T
for (i=0; i<email.length; i++)     . u0 l0 P# J$ ?  Z3 l# A6 B
  {     
# |! h" O1 X3 O  if ((email.charAt(i) == "@") & (email.length > 5))     
4 ~4 q9 w1 F, v, F8 k7 |( J2 f   {     
! U% ~5 Z" N, Y% ~% K* m3 ?( L' Y     emailerr=emailerr+1     
6 J( y2 q3 h/ ~6 c   }     ' U* X( `, f9 z) p
  }     
! s7 a6 C, `6 n) i if (emailerr != 1)     4 m: r1 ?6 n- `! k1 ~# J# P
  {       L, s1 ?* [: g: H% b9 q6 F5 ^9 X
  alert("请输入正确的E-MAIL地址");     ; R8 b' P4 @% A6 Q$ M- Y9 Q
  document.sform1.email.focus();     ( s3 X* G: _6 |; v+ y
  return false;     
8 o+ a8 p# |. r4 F0 ?  }           
: w" M+ W& M7 \: F& P+ [  1 k+ y3 D5 o. Q' J
if (document.sform1.checkask.value=="")
3 e- C0 D; f  r2 M  {
, H5 a, I2 `. @! j$ L   alert("密码提示问题不能为空");     
( G. b' v( R1 f- ^$ X   document.sform1.checkask.focus();     
7 `0 K" h5 j1 j5 z& ?3 R   return false;  ) j; ~; `0 S. \. U3 R
  }
2 X: l1 b4 z( a) W if (document.sform1.checkans.value=="") 4 W% A# I2 f' q, |
  {
6 M0 X% F. u) @8 w5 k* D. Z   alert("您的密码提示问题答案不能为空");
( [( j6 @5 t7 ^! p6 o$ A   document.sform1.checkans.focus();     
: Y: m* u* A( L" B% j0 V/ p/ q' _   return false;  
+ Z; G3 Q3 X/ @5 [6 b$ ~  }. _* f4 ?% b- f4 c
return true;     8 }& y/ r/ X7 b+ D$ G2 A9 O
     
# |& d* r- Y  x1 G* v: U' ^: q}
( I$ Q- d& `# h) e6 {' I</script>

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