返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
( a0 o+ x  k! {0 i$ T! w1 [: \# R<script language="javascript">     / G( @6 b1 ]9 I. ~6 W# J
function IsDigit(cCheck)     ; M/ `$ x; O- }: s# l
{     
8 A; `3 l: R( f return (('0'<=cCheck) && (cCheck<='9'));     
% Q: T+ o& P# b5 a1 I* C }     1 X8 U$ p/ M5 D& z5 l
     
( f# M+ ?  y, E; V4 lfunction IsAlpha(cCheck)     
# M, z5 N1 U2 D8 i/ Y {     , B( R* Z, k! a1 M( s- G7 s
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     , ]/ I9 |8 Y0 e  X  Z% \0 [3 Q/ I
}              # X* Z! f7 [; I, a/ V0 }0 D
      
) K5 J# Y8 y5 l2 X+ O  C7 Yfunction IsaNull(cCheck)         
8 S: p8 N' }: i& H6 H! h {          ! {, i' y  P7 }- p
return(cCheck != " ")         ( I' Z1 @* c2 o# }
}                               % W$ y$ U! N6 X5 w
      
* e9 T0 ^3 y! X6 Ifunction checkform()     
3 t& S& b/ }' i8 e" y% c{ 1 e- s8 ]/ V. h6 c! W( L$ S$ T" w
  id = document.sform1.id.value;     ! q5 X" P. H. r% D- c4 {
if (id == "")     , B3 P! g* t- G1 j( K
  {     
3 Y6 B2 A! Q, f/ h5 k9 c  r5 m  alert("请输入注册名");     + Z6 _$ |& t8 b, V7 O- Z
  document.sform1.id.focus();     
! E. j. _3 o6 y  return false;     
* s- G, h1 f7 E2 w% \  }     
& \* {* M) V+ l8 |( v' r     5 u# y& i8 x# Y9 |* f9 @, K; p3 s
for (nIndex=0; nIndex<id.length; nIndex++)     0 z7 ]# v4 A, R6 W7 v" J4 ]5 y
  {     
! b, W; ?6 s% D  J$ y. h  cCheck = id.charAt(nIndex);     
. P5 V6 c* C7 h! @  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
- V2 O$ o! K) z, a7 K   {     
! x# Q: K" b5 E! V  I9 H   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     2 O2 X# a! w$ D0 |' K' u. ]
   document.sform1.id.focus();     
) R6 f- ^8 R' R' @2 z" |1 t) d; E+ L% I   return false;     
+ E9 W" G/ F/ h! Z- v, G# [! Z   }     
- B9 r& |* I" E) b/ k, C  M8 W  }
6 X3 G0 g  Z/ D: W  R  U4 E' W  chineseid = document.sform1.chineseid.value;     ( N9 t* T3 n& ?" G1 H7 @5 {
if (chineseid == "")     * ~. v& Z* f0 ~  o1 J- A+ r
  {     8 B) F8 J: m8 Q( o  V0 m0 B
  alert("请输入中文昵称");     # {' l/ ?5 N" l5 r
  document.sform1.chineseid.focus();     5 w( }1 f0 `5 J& P# K: Q' H
  return false;     ; B- V8 q0 w; {  ]
  }   
1 W. S5 e4 F) t' n# l3 F1 w password = document.sform1.password.value;     8 ^. `( f7 B' K, F  Z# T+ S) }
if (password == "")     
7 D: z0 ^! O9 d; a6 ?4 D  ~  {     
4 e7 r! G1 s/ M. Q* p, M  alert("请输入登陆密码");     
7 F7 |- c' M/ c; Z7 x0 m; t  document.sform1.password.focus();     
4 G! E" E( {. O! v7 y4 n+ W  return false;     
3 S2 \  P1 d3 s# H  } 2 a/ H! Y, W* _. V; q, T3 W4 P
password1 = document.sform1.password1.value;     2 N5 I7 |( e9 Y" \! h
if (password>password1)     9 h; n0 E6 n$ C; T
  {. N  n% t. y" j9 R! m
     alert("重复密码与登陆密码不相同");     $ a" }; H6 u* J9 m. I5 ^
  document.sform1.password.focus(); , @7 h3 u1 {; ~9 c
                                document.sform1.password1.focus();     5 g# x2 E! R0 i! a
  return false;5 D7 z1 i  A& i
  }  & i6 _. N. _1 R+ u
if (password<password1)     : b1 D% {  ^8 |6 n
  {- H! w/ G0 p; j$ s
     alert("重复密码与登陆密码不相同");     , q! B' c4 W7 Y0 Q: H
  document.sform1.password.focus();
# D  i1 T. a$ Y" j                                document.sform1.password1.focus();     
0 Z0 j( g. B: O( g4 X$ @8 G  return false;
- c$ P9 p0 z) O  {5 @  C  }
4 O* Q7 G( J5 A; w$ O; b, x, Z if (document.sform1.email.value == "")     8 U, E7 i; Q9 W6 y, M/ A; Y/ G( z$ n7 J
  {     
" Z  v4 `1 M! S6 I, Q; ~  alert("请输入您的E-MAIL地址");     
; c* b! s' Z: |+ q" g% A6 W  document.sform1.email.focus();     
7 {1 g/ Y3 {# N) H; E! ?  return false;     ; |  n5 K3 e, B
  }     , N/ @, F- l* \$ n
      
# H# P; `# x( K9 b$ v email=document.sform1.email.value;      
2 T# o& I# ?' N0 Y emailerr=0     
$ c! ]. i, |" g for (i=0; i<email.length; i++)     
: h3 l& e* Z% B0 T! U6 H& ^) z4 G  {     
+ S1 Q1 V' I. w  x; X! m  H9 R3 V  if ((email.charAt(i) == "@") & (email.length > 5))     
7 Y- t1 \+ x6 }( J   {     
  a. a& N! i. b8 h8 D" {; e     emailerr=emailerr+1     
6 K# R; ^) O0 E( Z+ _2 }9 J# {1 \   }     6 `0 X( ?5 {. @! \% X1 M
  }     6 P4 V. q# O/ o  y$ h6 f9 h
if (emailerr != 1)     
% y! F' d3 x" K  {     1 ~: p; o! m; R# b( e5 Y3 n
  alert("请输入正确的E-MAIL地址");     $ }, f) `) J, K! `' U) P( a: i* G
  document.sform1.email.focus();     ) Z! z1 s) {) G* [8 N8 g  }
  return false;     3 f; u# X2 E4 q7 f; P4 K5 J
  }           ! d9 r& ~, U$ ~
  % ]& Y* M2 R3 N6 F
if (document.sform1.checkask.value=="")
! V1 `2 ~# ^: k5 C! n1 Z7 ]  {
: `$ B) u4 k+ _, B1 Q  ~# P9 S   alert("密码提示问题不能为空");     . P6 K1 H: |4 U# {$ U/ }
   document.sform1.checkask.focus();       w/ @, Q0 t: O; B( F! k
   return false;  7 n7 {% q- L# T9 z: Z
  } 5 ^& F5 ~' Q! C, W. U: m
if (document.sform1.checkans.value=="")
. |; A3 ^& c: B8 ]  { 5 H0 r' x$ G+ ?; [4 O7 ?; f3 ~$ Z
   alert("您的密码提示问题答案不能为空");
4 X: f4 W# h: ?% ~9 N3 s   document.sform1.checkans.focus();     8 t7 ]$ N3 E6 n9 G- a
   return false;  ( T5 `- l% J; _
  }
0 v( d4 R( ^& H. C/ l" e return true;     
' }4 t' d/ \3 V; k% s     : ], b" w% C6 }4 l3 r
} 5 p! M$ @  }8 x* }$ N
</script>

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