返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:2 W4 Y2 U) }& {7 n! s" l& T% l
<script language="javascript">     ; L, t, {# i3 q% m+ L
function IsDigit(cCheck)     
  X6 S2 F1 Q9 {% N! S4 h7 ]& e  w {     
1 T& ~! w" I+ u# I, W return (('0'<=cCheck) && (cCheck<='9'));     3 Z2 {5 D. [2 Q+ D: ?1 n
}     
0 i8 W/ }; n1 i+ A     9 B: Q# I) l7 \3 {# L! T# Q
function IsAlpha(cCheck)     
& l  L! \& ^  [' b1 j {     
  z6 z, a% _5 p# R5 n7 ]9 r return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     & T$ _. N. E  n6 M5 h% n+ ^
}              ) }- Y& S7 B/ ~
      
3 \/ L& O# \  l7 C3 ^2 Hfunction IsaNull(cCheck)          ! [4 L, K8 q" `# H. X* m, y
{         
, E/ ^9 R  R  l- _ return(cCheck != " ")         
9 i7 p# h# [3 a, t }                               : R# `3 j# P* V" E# P; F& i
      ; g3 z2 Q; s4 J4 Q
function checkform()     + V+ d, Z" Q7 Z3 g2 \
{ ( f: g5 G  _. @/ D  k8 N7 p; g6 G
  id = document.sform1.id.value;     3 R, F$ f7 O' _& V
if (id == "")     
" v9 [6 ^9 V3 |# I" R  {     3 X0 f. X( k% `* p' F4 {
  alert("请输入注册名");     
% t: D, }' F0 W6 y3 l2 [1 l$ G- j  document.sform1.id.focus();     
6 [5 D$ n  C9 e2 T. C  return false;     6 _2 Q7 M* T, Z' M5 R) Y$ L$ d
  }     % `* p* ~& u0 w5 |
     ( ^, D- ~8 ~! k4 k, \
for (nIndex=0; nIndex<id.length; nIndex++)     $ b8 J% P7 c$ b. |" |( U) B
  {     & R& Y; I1 Q! I! q! _
  cCheck = id.charAt(nIndex);     
' H1 S% B7 e9 ]( B' X  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))       W0 k/ _% E3 D0 \7 ?( S+ }
   {     
% O, s& O' t1 S7 `0 U8 L" g) Q   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     " Z& Z4 g- f  V1 \7 D* u! I
   document.sform1.id.focus();     
+ ]4 _' h3 e! d: ]   return false;     8 `+ o* j. \8 s2 z2 e: D+ H
   }     , O% j; d+ q0 m  x; m. p3 V
  }
" U6 v- \3 U- A# X' t! P  chineseid = document.sform1.chineseid.value;     
0 ^/ B" i# }! [ if (chineseid == "")     * Y7 l; j5 l; l% Y
  {       U* ^# E/ \- ]. o
  alert("请输入中文昵称");     
5 v# A! c/ j* X# W5 d7 P  document.sform1.chineseid.focus();     
5 t5 \' |+ f5 k  `  return false;     ; D4 t# g" X3 m) j: g
  }   
% K& b. }$ o, Q4 H" E" @ password = document.sform1.password.value;     . O5 d2 G% e* b( q3 e
if (password == "")     % b5 b% v6 |( o2 [6 A* i
  {     
1 `# w2 A: ~; f5 D' u  alert("请输入登陆密码");     7 Q; s4 c" j. K& g1 U5 Y
  document.sform1.password.focus();     9 x: C9 o) c- H0 P1 r% p' }
  return false;     
: X5 ~7 t! m3 `, Z  } / g) k& s; t7 Y3 ?2 N5 r: l
password1 = document.sform1.password1.value;     
9 N3 Y6 N0 M4 k! }& E/ | if (password>password1)     
  D% B; P4 y6 v  {! ?9 {6 h" P  K( Y/ L4 E
     alert("重复密码与登陆密码不相同");     
1 t& z; K! B4 a, t  document.sform1.password.focus(); 9 Y/ N" f8 J6 i0 q+ w4 Q
                                document.sform1.password1.focus();     
/ b% S6 ?3 a* }; p! t' a* z2 |* }0 I+ F  return false;, t5 I. H0 k6 R: G9 E4 Y2 H
  }  ! T& h3 W. g3 S* n
if (password<password1)     4 G) Q. g+ P9 n- s/ o/ w! l
  {
( w) c1 s/ s1 z5 l     alert("重复密码与登陆密码不相同");     
' P# f* c7 Z6 D, N$ J5 s! g% T) I6 w  document.sform1.password.focus();
+ t: Q  Y( X+ j; t$ [, l0 o% t                                document.sform1.password1.focus();     ! ~* |' S6 Y0 y0 c
  return false;& y) y0 W% H$ v) `: a9 q% `
  } : a3 h' }3 d  x+ a
if (document.sform1.email.value == "")     ; C5 ^) X& ~6 v1 T9 Q1 f5 R
  {     " ^/ _& U' m- o6 B
  alert("请输入您的E-MAIL地址");     7 p  k5 A! g' M4 K9 @0 |
  document.sform1.email.focus();     
9 b8 V9 a3 b, `( V8 W  return false;     8 X5 U/ v& K8 q" t5 L6 B
  }     
4 D) c, d7 d0 ^# P      
$ E6 w& x! n) D9 N4 n! {5 X email=document.sform1.email.value;      
4 b# q" \, w$ ]+ ]* Q emailerr=0     
  b# ]( E2 `  a# G: g for (i=0; i<email.length; i++)     
& J! S% a" T5 M% E  {     4 S- e; `- n7 f/ X6 j
  if ((email.charAt(i) == "@") & (email.length > 5))     
( |+ m% {9 J9 ~+ l" B& o   {     0 e* z( I- w, C/ b1 x( G
     emailerr=emailerr+1     7 @, T) O: R2 I* [4 }: t8 U4 O
   }     
' H2 e; F4 d/ u- B9 B# S+ z  }     
9 K/ l) Q, P7 Z" _ if (emailerr != 1)     
! C% i% _0 e& ^! X* H9 U* O0 X  {     
* |0 l( `6 ?+ u  alert("请输入正确的E-MAIL地址");     
3 }* G( b' O3 x3 r9 }  document.sform1.email.focus();     3 o" U( O  u7 H0 f
  return false;     
# C9 f) z: K& Z' o  }           9 l! t* J& [& h# w0 e" s7 W
  + c" N* S! ^2 C; h! L( S
if (document.sform1.checkask.value=="")   W3 E% ~7 H$ Y! s/ X7 [8 @/ f4 Z2 E
  {
" ]6 k1 Q1 ]7 }: g0 t! W: o6 B2 r   alert("密码提示问题不能为空");     
9 M! U7 H4 t  a3 J# o9 C   document.sform1.checkask.focus();     
3 D% b8 l! p7 A' I   return false;  
' U6 c' F5 l9 j/ G- r8 m  }
$ X# @3 X- H: ~- `2 }, q if (document.sform1.checkans.value=="") 1 l/ @: i5 R; R: }. W
  { 5 c( N9 N7 c. g( ^, o) ]
   alert("您的密码提示问题答案不能为空");
( I0 w" G$ ^/ b# h   document.sform1.checkans.focus();     $ Y  c: N" ]' J3 _9 |* g4 s
   return false;  
+ a' u2 Y0 `9 r  }; s7 b& m! F5 S$ i9 a
return true;     4 G3 \7 M' e, y) z% b# H1 r& h3 H
     
+ V; Q% C4 Q: h3 q}
: `. Z3 c8 y( h: c# r</script>

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