返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
- P/ l$ T, V- d( J9 a6 I2 J<script language="javascript">     
' c5 Z: r  Z0 B  m2 Z8 z$ p' Efunction IsDigit(cCheck)     * b* c! j. z4 o0 I3 v
{     - ~; P$ R: r3 q% S5 p( {
return (('0'<=cCheck) && (cCheck<='9'));     
, a" R+ U( c4 H  B  e8 V' d; r }       `5 A/ U2 `& m4 p! V* d- Y
     - [/ A) w! g' X. H) v7 a0 A& i
function IsAlpha(cCheck)     
- \0 s4 m! H; Q9 M' P# d+ c+ m1 ? {     % e; h; {/ V. Z, F/ ~
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     0 r4 g- a  ]0 [  o
}              6 i0 J2 q5 _% T6 Z, J* Z2 r
      
7 Y! i9 m* l( Y! b1 yfunction IsaNull(cCheck)         
/ M7 u0 Y* r7 \! s6 K! t {         
  @$ E" }- f' O return(cCheck != " ")         
  T! u1 x  Y: w1 ]! g- w5 ?7 | }                               ) j7 {. v4 s% }
      , k1 @: W- B" L" l
function checkform()     
+ `- I7 ]$ S& x{ 5 W2 }( ^( E! `7 K9 r$ C8 }& s, d
  id = document.sform1.id.value;     
5 b: o2 ~) q7 }" W3 g if (id == "")     
' N: a: R, Q; }" a- T9 q  {     
) r4 i; u, X5 C( g  alert("请输入注册名");     
+ d1 N* _9 G) V" u1 d  document.sform1.id.focus();     : W. X' U# V7 n# z$ A+ L
  return false;     
; _, F3 x& M, I& M4 W/ ~  }     0 c  ]+ K: c7 U. u6 h
     
, O+ j2 p! _2 S! k7 o0 ? for (nIndex=0; nIndex<id.length; nIndex++)     
8 n0 S9 I. D# P2 m2 u4 L  {     
2 t; O$ p0 C9 i! v- j+ r  cCheck = id.charAt(nIndex);     
5 X: S2 u5 L& V  G  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
  |6 A: B1 i" A8 ?, q7 l   {     
5 u' G/ n$ r1 O& K6 C   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     # j5 Q$ J" z# l* x1 i5 i
   document.sform1.id.focus();     
9 |6 L/ O8 Z# i   return false;     
5 W6 N- }  F. V- d' I5 Y% o8 _   }     
( v! ^$ e/ ]$ H. x5 U4 Z$ b  } ! d& P$ f/ ]- v9 K1 M
  chineseid = document.sform1.chineseid.value;     6 p( m# y5 d6 l" o
if (chineseid == "")     
4 A. V# w6 Z) d) E4 V6 W  {     
6 d3 u# ]7 l) s( j+ X4 b  alert("请输入中文昵称");     
1 e; ^% N" @! g6 G0 t/ }) g  document.sform1.chineseid.focus();     3 l  _+ V2 {% x3 G6 d
  return false;     1 x1 G, x  c6 s0 m
  }    5 |+ L2 Q# F  j0 @( F
password = document.sform1.password.value;     
; B% r: m8 ?/ q5 X4 w3 S& X if (password == "")     1 F* V0 D' v2 w) e6 N8 E
  {     3 d; D) M- Z) f2 R, ~# E
  alert("请输入登陆密码");     
- z) w4 L/ ^5 f2 w0 ?1 o  document.sform1.password.focus();     2 O7 B; i5 e2 Z6 @- ?3 w& |4 T
  return false;     
/ ^$ M7 P. I  m" w; f6 u% g0 ^  } # x) ^% \  y1 [$ p4 z  r) b1 j
password1 = document.sform1.password1.value;     0 D# H3 j4 z8 U( [/ V" d; O
if (password>password1)     
# {1 ^6 T* h4 Z" e) N9 g; K  {- O& A3 \# W' R2 }% o6 @6 Y5 T! C
     alert("重复密码与登陆密码不相同");     
: u, r: ]8 S0 K5 Y, E9 G  document.sform1.password.focus();
9 E. P, ~4 C, |: W2 S( y                                document.sform1.password1.focus();     1 b7 ^! X- j0 `2 |* U' P
  return false;$ f& u1 }* X2 i5 Q8 S- ~
  }  7 P" i6 l9 `. e- d  t
if (password<password1)     3 p# H" O6 B9 i2 m
  {
/ g  \/ d" N9 C' d     alert("重复密码与登陆密码不相同");     
; M7 ~6 [1 L: Q' X4 q: M  document.sform1.password.focus();
: {! O- ^2 M! ?3 ^9 S3 P- g                                document.sform1.password1.focus();     1 ^$ E4 b! {2 f" |$ a5 l% {
  return false;# Q" s. K: ?; M* f# Y; t- ]3 s
  }
4 b# r) \( ]+ K- L: g4 R2 U6 r6 Q if (document.sform1.email.value == "")     
$ [" E6 D; j- T7 a+ N6 I3 Y1 o- [  {     
6 e, L9 l5 J9 i4 S  alert("请输入您的E-MAIL地址");     7 }( q- p: t4 q% `( p2 {/ Y
  document.sform1.email.focus();     
# h! F* T1 q  @) K# i( n, y5 z8 _  d. I  return false;     $ |' A6 [9 ]3 F
  }     
( H# C( k' O" \, i9 u- h      
  w+ ^6 \. G: Y) |" o email=document.sform1.email.value;      ) Q$ P1 I# E5 b2 c8 g  C
emailerr=0     
; y( l# b9 B" J: x) h6 r$ \2 v+ | for (i=0; i<email.length; i++)     
  {+ q( P' {, a# {0 K4 v; B2 Q( I: A7 O! r  {     " L, @0 R; ^0 v, A) M, s4 O) A
  if ((email.charAt(i) == "@") & (email.length > 5))     1 w( z" d0 Y% j4 r6 ~- t
   {     
" {7 W* q3 ^1 G2 E+ Z6 u! n) z8 u8 H     emailerr=emailerr+1     ! B8 t% j" h  v9 P, _8 @" w  J- V. z
   }     8 D3 F; d2 q" {8 h0 c
  }     
, R% e* l2 R/ x5 O, F if (emailerr != 1)     ; g7 b, G& A) k/ K7 x, r+ C
  {     
1 J1 N$ \7 I! h, |  alert("请输入正确的E-MAIL地址");     ( ?$ W" _( e! _% n% {
  document.sform1.email.focus();     / i; v* @  v+ a4 m! E
  return false;     
7 Q/ {$ ]2 `( a# e# Q  }           6 Y3 c# I: j0 M) a4 q
  0 D" X( }3 b, _; m8 K; l3 R: r0 M1 z
if (document.sform1.checkask.value=="")
. R, d; T: U& E' i( s3 g  {
% N! i5 a* d2 L" k. \; [   alert("密码提示问题不能为空");     9 K- K; S8 V4 i) H: C
   document.sform1.checkask.focus();     # S3 W6 e' o$ p# \5 e& S0 j
   return false;  
" j' x0 k* t+ p4 N  }
" \  b1 W5 H, Z" M0 t1 v if (document.sform1.checkans.value=="")
6 v# j7 T. a8 y+ V  { ( n# r9 x  t7 U/ O% A
   alert("您的密码提示问题答案不能为空"); 9 c. }7 D" }. t/ e2 O  {5 r
   document.sform1.checkans.focus();     
- q  P+ h# ~3 |, M1 j1 @   return false;  ' p  f/ d$ J% Q: @. H
  }% E0 ]# I: {' h2 s) _% q$ I3 a( o
return true;     
  G& l* u6 y7 i! L* @* f- F     
  q8 j" J9 j' j2 ^9 B9 `3 e}
/ H+ h) [4 Z3 n1 f  d/ x</script>

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