返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
9 x; J- {: {) Z3 m, f! S<script language="javascript">     : Q; m, k  R4 H
function IsDigit(cCheck)     
! O; m/ }5 d3 v" |7 ]/ j4 t! Z' N {     * A0 d0 z2 p; g2 Y
return (('0'<=cCheck) && (cCheck<='9'));     
( ~) W" _" K, \/ G }     
- h/ D" I, V/ z) l3 M% D; l# e     3 M7 W9 q' K# r; V% ~  T/ S
function IsAlpha(cCheck)     " ^6 b$ J  M6 ]; g' \& L' C
{     5 e8 r; @- g3 j8 d. q9 ]$ H
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     , Z& \. N; V0 j% Y$ ?
}              
- t" B6 N2 |4 a$ w# D      7 V. n) E% @$ u$ G4 Q* m
function IsaNull(cCheck)         
# S# f% |" L* O3 f {          . z* j4 [2 Z8 P2 n8 T! z9 q* X) ^
return(cCheck != " ")         
, z0 L- E, f; E8 W% |' G2 u }                              
) _* h/ X% C$ D& A      
$ M/ a' }7 a% Dfunction checkform()     
* }2 \: }% S) K5 B/ k7 Z{
9 R' h$ f0 h; V  id = document.sform1.id.value;     
" E" L# o: n6 k9 D! R, G if (id == "")     
$ o4 t3 V2 {. Z* Q. W7 m, o  {     
5 \+ C4 \0 O) t5 D" Y" S  alert("请输入注册名");     
( G: e8 }; S% Y- S, r6 I5 a  document.sform1.id.focus();     
( Q4 e4 C0 b# s& R& k) y  return false;     
* \0 I5 K: F) i* d, L  }     7 X) D7 V% w2 |. I$ Q( Y
     / W3 g' D# k& ?2 H5 a+ d  W
for (nIndex=0; nIndex<id.length; nIndex++)     
2 s: U7 j- A6 B4 N$ A7 [9 l  {     9 v- }( Q& e/ a4 d
  cCheck = id.charAt(nIndex);     
( \8 H3 P7 F( P7 L% o- E+ D$ Q  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     : M/ m' }* s9 d* s
   {     & N. e) z2 _, Y8 L& m
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ; E: f# l0 h/ o% l9 k+ E# x
   document.sform1.id.focus();     4 a) y& E( T, s/ a0 o8 b+ G# H' Y
   return false;     
9 d. t& R" _" X- O" l   }     & R8 R* P* r) t, [
  } $ d& {& m, g: h  I5 X. S3 T1 X
  chineseid = document.sform1.chineseid.value;     
! ?; P4 H7 o7 s" ?3 T* e if (chineseid == "")     7 P1 u; ]4 l' M3 N$ x
  {     
' J5 h0 p" s: M) G- e9 \; y  alert("请输入中文昵称");     
: y" R- @2 F) }! K1 r  document.sform1.chineseid.focus();     & J6 M" ]$ x) T' N: R- q
  return false;     . E& S" m% V) Y1 z6 o
  }   
* h* O4 P0 E" C& ^$ _& ] password = document.sform1.password.value;     
: _# X+ T4 J# `7 O2 k+ b if (password == "")     
- o. t- e0 ?' A7 ^  {     3 T8 ]. f# V3 V. H- u% @4 m
  alert("请输入登陆密码");     
1 Z$ Q/ d* A; \( H+ a  document.sform1.password.focus();     
  F7 Z' u( b% \0 M' T4 ^  O  return false;     
+ r+ q( I5 }6 T4 W! d' w+ h  }
& ~6 R2 v4 E  v3 Z. {) q" a password1 = document.sform1.password1.value;     * o. v- T2 i3 f
if (password>password1)     
$ ?* T9 S. v4 N  {$ q% ?+ I* d% E* [
     alert("重复密码与登陆密码不相同");     + M9 v/ u  b  Y4 O, W
  document.sform1.password.focus(); . U9 Q, Q% @4 H0 x5 f8 z3 U
                                document.sform1.password1.focus();     
. w# c- @# w* h% x  return false;! N& c9 N* J& c& t! j
  }  . n; q5 w+ s' j' [: [& c
if (password<password1)     
: J, J8 r& ^( H- [8 d  {
9 x8 l" @( G0 Z8 C9 H     alert("重复密码与登陆密码不相同");     
% n1 @: Z3 z* N, K( J  document.sform1.password.focus(); ) F8 D2 P/ I0 b- i; }
                                document.sform1.password1.focus();     8 a; S" a# _8 _( }2 F6 F1 y
  return false;/ l& K' c  C* a% u. S9 t
  } , t& |7 J( Z8 @
if (document.sform1.email.value == "")     
) U6 q5 e* |" A  {     : v) z. o$ Y1 F! ^& z
  alert("请输入您的E-MAIL地址");     
0 ^- j' _  r# m5 T9 k5 a$ t, P  document.sform1.email.focus();     4 j$ T, o; B; j! |5 N( X
  return false;     
6 \4 z+ o8 U7 J- x: C) k1 {: u  }     
& B) D5 c5 I9 X      ( D. g# J  Q: K2 a) @
email=document.sform1.email.value;      5 V+ f/ d2 ^( I6 O1 C( I
emailerr=0       i  r: h& Q+ c: F" a
for (i=0; i<email.length; i++)     ; U( J" s6 k; M  @! G, v
  {     
+ h) I# S) j  {' w  if ((email.charAt(i) == "@") & (email.length > 5))     9 c& `0 l( M  X3 W5 u+ D: B
   {     
0 A; `1 T. ^# T0 e- p; n     emailerr=emailerr+1     
7 Y1 V+ y& h' D) ^7 Y& r. v   }     ; Z  Q% d* |; E! D, o
  }     
  |& M$ T" q* B0 z" H/ I if (emailerr != 1)     - J6 J+ X( T) W7 j" @
  {     $ `9 ~* D# q: p; S& b) S$ {# ^
  alert("请输入正确的E-MAIL地址");     
. B* c% P1 W* \$ ~( e( }  document.sform1.email.focus();     
6 }& Z: z1 \" Y& T" s3 W  return false;     1 [* h0 [: W' |! a9 e
  }           
) u  Y/ ~$ C/ Q. S$ W7 O  
  Y7 W$ T/ P0 m/ W; c6 W+ C if (document.sform1.checkask.value=="")
" w1 P+ k4 _: K5 w' ]) U; h  {
6 r6 y0 \) b; }, i! P   alert("密码提示问题不能为空");     
6 t2 m' Z+ N, E( b0 |0 F+ ?   document.sform1.checkask.focus();     1 m  Y: N6 k- r# n$ M
   return false;  
, q8 x) H0 \! b! g9 _  } , D% E' V) V! x2 Q1 C# ~6 z
if (document.sform1.checkans.value=="")
5 g- s; s# |4 Q4 x9 c  {
' A% d3 |: d6 Z7 H- K7 T, m6 V   alert("您的密码提示问题答案不能为空"); " K5 l7 f. p+ a% I( U
   document.sform1.checkans.focus();     
8 _3 U, I! A$ l6 q' Y6 D) q   return false;  ! p- h2 Z$ Y7 h( {# F  K* o- R
  }
% @6 y# Z0 i; n, s$ h0 M return true;       x- W8 o3 r# r6 ?% b, _  ]
     
5 k4 W; N1 s6 W( f0 r/ X9 {}
  S6 g9 h" K3 d</script>

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