获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:# `4 }7 c. C9 I: ~
<script language="javascript">     2 `' H+ h- S$ i9 K  ]& y
function IsDigit(cCheck)     % K# ^- ]' A' S+ S4 g1 A4 n: w
{     * ?: l  D! P# T* ^. m' c
return (('0'<=cCheck) && (cCheck<='9'));     
3 N, t2 n( X; @* F: H  y( d }     
7 ?- V( X. g/ [* J! x3 r     : F7 j, b; x5 B: {& i
function IsAlpha(cCheck)     7 ~4 b8 z; z' q. H: g1 q
{     
. N7 A5 c- x8 g' i return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
+ x6 B, k& o. R9 F }              / B- {0 K! }7 P4 D  ~
      
, O% N1 o, _( Q  `4 J. O8 [) Vfunction IsaNull(cCheck)         
8 S' L" r( X* a! v- A0 F- f, O {         
8 I, ?  `% c" G: y return(cCheck != " ")         * y% ^5 ^& f0 H# q
}                              
" W- J8 Y- v: D* ?6 t4 y      ! R( Q) y. l  ~6 }
function checkform()     
/ K$ d) |# ~2 t{
; V; ~, K* X, Z' d: `* }  id = document.sform1.id.value;     " e3 \" b) h: \* y
if (id == "")     
0 C  X; D9 ?* F! M4 F# ]  {     - K6 T; k4 u; [1 G$ q
  alert("请输入注册名");     
; |8 J1 l- C; T8 W$ l  document.sform1.id.focus();     # [6 u6 j# y# t  |- r
  return false;     
0 S* P* L. r4 Q9 S2 S: N1 M  }     ' k$ `( R3 ^7 A0 N( k. a$ Q2 Z
     
" _  K; h- E% @- E4 _ for (nIndex=0; nIndex<id.length; nIndex++)     
, L4 r% M7 x6 ~9 v; m( ^: D/ Y6 V( a  {     * U; n, a' N4 s+ A! k+ w! e7 |
  cCheck = id.charAt(nIndex);     7 ]- a1 i5 ?2 E0 y: w7 Y
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
$ O$ g; q3 }' K7 j5 {   {     + t# h: z" H0 S( E
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     6 r+ z+ J5 w) b" K6 H0 l
   document.sform1.id.focus();     
9 O# G" E2 y. C7 l& v3 f   return false;     
, K/ Z# I  E+ ]2 F   }     % ?! P% A6 P" r! ^
  }
" V/ _7 k8 I) h; M- i  chineseid = document.sform1.chineseid.value;     % n1 g; |% r+ Z
if (chineseid == "")     
: H3 c# g+ e- x& ], M  {     1 W) N  i5 P/ r7 P  r
  alert("请输入中文昵称");     
6 E( l- }/ x. Z# g6 @8 J  document.sform1.chineseid.focus();     
" [4 l, p0 S  t& A' Y9 ?  return false;     
/ |1 ^% `, i7 o! f% B7 U/ C  }   
( W- V- T! w7 M password = document.sform1.password.value;     4 ~3 d- e+ T% ^8 c
if (password == "")     
- `* l1 [0 ?& t2 d' A  {     6 y" a. x1 z0 {
  alert("请输入登陆密码");     
! T5 M7 N9 ]: y8 n4 s  document.sform1.password.focus();     
4 g& V6 X% w" \5 o8 d$ T  return false;     
$ b5 P* F" G0 c( P  g% N  v  } ' x" A2 D! W2 D5 k- A% S3 R: I7 M- t
password1 = document.sform1.password1.value;     2 ~- {) K2 \3 v' W
if (password>password1)     
5 v5 Y2 D" x' Y0 T+ S9 x' j1 O  {6 Q5 z8 u9 W, w7 G
     alert("重复密码与登陆密码不相同");     , |$ x0 K4 s1 ^- c* ~- q! s
  document.sform1.password.focus();
; q/ B8 K3 }2 k9 Y% d# E                                document.sform1.password1.focus();     
$ d  z0 T1 G4 c! f- U  return false;6 o# m/ _0 c. D! J
  }  
' _, p5 _% K1 ]0 Y6 mif (password<password1)     
; Y/ S8 ?& B6 S* d7 e3 f5 k  {
6 [3 s" N; S5 g1 q" Q% u/ e" }     alert("重复密码与登陆密码不相同");     + A% P( U  L- b: z0 A7 `
  document.sform1.password.focus(); - h9 f. l5 ^/ O# }9 N- w) l' v
                                document.sform1.password1.focus();     ! K2 L4 n" u2 Q
  return false;
) R0 M, V, _0 y: B  }
7 p) P8 _5 b/ G2 V6 W6 [. y4 |5 n if (document.sform1.email.value == "")     . p9 o' C$ V/ G3 c  j- L: A
  {     9 @4 J' Q1 F, C5 m' e
  alert("请输入您的E-MAIL地址");     
/ ]! Z% d% d1 \: ?' u/ N  document.sform1.email.focus();     
/ o- X- S6 @1 r6 o8 j9 U  return false;     2 S8 Z6 Y+ _, Q5 c2 R. z, x: d7 k- \
  }     ; u5 D  a  w1 K& W7 K
      
# B+ A  W. j: t, T0 E5 r email=document.sform1.email.value;      
8 H: N4 U. H' j$ \ emailerr=0     
8 |- w  B. {0 ]+ R* @( J+ w for (i=0; i<email.length; i++)     6 w1 k* I; P9 J: ?/ J; ~
  {     1 g) e& I* ~  U- F& v- Q
  if ((email.charAt(i) == "@") & (email.length > 5))     
4 G. U+ f; F9 l6 A7 N   {     
) K3 C, e: U' f7 V* _( b     emailerr=emailerr+1     
( ~" l5 c0 ^  w0 g   }     9 J5 v: w( Q( {. R/ T
  }     
& d- }2 u) T3 b5 ]' L3 c if (emailerr != 1)     
8 [7 L2 D1 L. @! d& D; q  {     
1 ^  _# x. f( _- q# P! q  alert("请输入正确的E-MAIL地址");     , h; h2 Q% ^, R7 c" N' @
  document.sform1.email.focus();     
4 Y! j* F' c/ T) @* j  t  return false;     
& Q; Y: L9 r$ {2 ~0 X  }           
2 L' z4 ]1 c7 a" {$ T  + t  Z* J# F* d4 Z
if (document.sform1.checkask.value=="")
2 c, Q% x/ j; {" F! b  {
' w1 t1 ~8 |* i* }# Q  x* c   alert("密码提示问题不能为空");     % r. v8 Q& }3 J
   document.sform1.checkask.focus();     . @" z8 c# K* A3 m
   return false;  
" r- e; U3 A" s4 d4 r- K, D: H; }  }
; m4 B! ~/ v0 }" r4 U* ^4 M8 V# r if (document.sform1.checkans.value=="") 3 W( q2 F3 g0 [. m8 S. K
  { " u* A  h+ n' W* ^" @  s# R5 n
   alert("您的密码提示问题答案不能为空");
" N1 d& d0 D* a7 I0 H# S   document.sform1.checkans.focus();     7 T1 \- p, v/ r: f; B4 q
   return false;  
$ |* p- I* T: H! t  }/ _# P8 i! Q1 l% R
return true;     ' O0 O) P  I4 \8 U8 _# g
     
7 ?4 a( ~: L2 m1 n" m# {}
& D; Q0 N& G. I4 b& {; {3 `" P</script>

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