返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:4 [+ t5 v% l% I+ `- M  b
<script language="javascript">     $ a3 q6 r* r) \/ ]
function IsDigit(cCheck)     
+ H  ^/ D+ m3 Q {     
( H- F& U7 i8 f. ?! c3 Q return (('0'<=cCheck) && (cCheck<='9'));     
- I- Z- w. x! I }     ; i. P; {3 w, _/ g, P& |! V- a' y
     # e& a( [, W& z2 [5 f
function IsAlpha(cCheck)     
, B' p; y+ z2 b3 }6 V$ Y {     
3 l( |. I/ j+ ? return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
  M! t- P- x5 ^: ^( ` }              
5 v# s/ Z0 b% O6 {" W5 x- S+ [      
9 q* R2 N/ `* X; u) Wfunction IsaNull(cCheck)          ' h. t! O* U& `5 y$ W* M% O! V8 m
{         
. M/ j, S+ E- O0 \8 K0 U return(cCheck != " ")         
5 o+ L: C5 {- @. C- f/ ]& v }                              
" C6 _9 R# v" t8 a4 P& B# E2 |+ b      
* K% y8 H: [7 D0 Q, dfunction checkform()     , Y! v: Z* |6 U- h' J5 y+ M
{ ) |6 f8 [0 s4 v* n6 f
  id = document.sform1.id.value;     * v, @- [6 ?  {
if (id == "")     
! S8 L. |# c5 K9 N' ^- g. J$ [  {     2 V9 {9 R0 k6 l- w  |4 M
  alert("请输入注册名");     
! b* d& Q5 u& B$ r' F$ E  document.sform1.id.focus();     
1 ]0 t% X# m6 N& }3 {0 \/ p( q  return false;     
2 O$ x# k4 l+ K9 [! `5 _  }     
' ~; ~- e! W# e4 {     , G% z5 Z8 D4 }; v: s6 ]. y9 S+ {
for (nIndex=0; nIndex<id.length; nIndex++)     ' \3 t3 [( G4 E# f- D4 b7 s% z
  {     / ?/ v+ @9 c5 Y% q: r
  cCheck = id.charAt(nIndex);     $ M0 t4 ^( e3 T
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     $ n) Y. E6 h8 P- ^+ P& a5 F! Q
   {     
: K. z& O7 m# p+ z8 q$ L   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
# g, Q) y, L: \) H   document.sform1.id.focus();     
+ {" j  e8 {( M- u" j. V   return false;     ! ]1 a% J. Z5 G: V5 }8 r& h
   }     + h0 c6 Q) W2 `" P5 p
  }
) X3 K" Q$ l( h9 _  P# ]  chineseid = document.sform1.chineseid.value;     ! ?" B) K6 b6 r; S
if (chineseid == "")     
$ B9 v: h- v5 z  {     
' n* Z- ~7 e+ q7 E$ I  alert("请输入中文昵称");     
( D8 V1 R9 S$ S  document.sform1.chineseid.focus();     4 a& R3 Z% N$ {
  return false;     
& K0 ^. Q- |# _. y, T5 W7 y  }    ! o/ Z( P5 q. H! F
password = document.sform1.password.value;     
4 ?; K5 ^0 l$ A4 Z& L- Y/ h6 C9 B if (password == "")     $ {. L1 [: P) z: Z3 g. R
  {     8 t; ]$ }$ z7 L5 H0 Q- L/ L. X3 r
  alert("请输入登陆密码");     
7 m! U6 X7 l0 @+ N- Q  document.sform1.password.focus();     
! N- q1 \2 V# N( C1 p  return false;     
6 t: L& F6 I; l6 O  D: p+ `- J  } 7 r* C! H, I/ }: E# Y5 L
password1 = document.sform1.password1.value;     , N: D" A6 Q9 g5 G8 ]
if (password>password1)     
" M1 w* i+ J) i% m1 B6 p- Y/ i1 O  {' k+ @" S9 \9 m- F1 |! a9 D( V
     alert("重复密码与登陆密码不相同");     % t* k+ P; x8 {
  document.sform1.password.focus();
; D' u, D  f9 A% d/ H                                document.sform1.password1.focus();     5 `% d6 o0 z% O4 r5 p7 n& x9 E/ `
  return false;' n$ K& H$ z* N+ j2 @2 H
  }  2 c; n5 ~( M1 D' `4 W
if (password<password1)     
5 h9 r: o5 Y1 n2 M* c& e! ~) N0 `  {) [" x4 w4 r5 N/ F! H
     alert("重复密码与登陆密码不相同");     6 J5 S" H: [) P/ i
  document.sform1.password.focus(); 8 m0 V4 c1 \2 v* f2 x# A% n* O3 c
                                document.sform1.password1.focus();     
3 f$ T  {! z8 [  return false;
  d7 I4 ?  S. Q+ h9 H! [1 t  }
% U" L0 C3 p6 ~1 n if (document.sform1.email.value == "")     
3 S2 _# \8 W; n" w1 P  {     
- M' _% L2 d& c4 _7 {1 W  alert("请输入您的E-MAIL地址");     9 a' J: w% `9 w: S! Z5 g& P* M
  document.sform1.email.focus();     ( H9 m8 U) U+ n; P
  return false;     
; l* E& x9 w1 f# x% _7 @  }     & G; r3 X" B; E- [0 L1 I! J+ W0 F) Z7 T
      9 v0 y9 G5 i* C9 l3 ]
email=document.sform1.email.value;      
1 Q( C6 `, S' _4 J3 v emailerr=0     - {& J- z) o% D
for (i=0; i<email.length; i++)     8 L5 O- t0 A! Z* W/ s
  {     % D8 p5 v! ~8 ^! l8 ]
  if ((email.charAt(i) == "@") & (email.length > 5))     0 q! x4 B# s3 g% Q
   {     / I5 E# V0 M* u6 I
     emailerr=emailerr+1     
  J+ S4 l% X/ \* k' q* m7 K   }     7 G1 z4 H3 P( B* j+ A4 k( D3 N
  }     
2 |0 |/ h% J# a% s& T if (emailerr != 1)     
/ c; o! K' U& r! _  {     
; Q9 z  ~  b4 M, \5 O; j  o3 _  alert("请输入正确的E-MAIL地址");     
1 L: A  m3 R; Z. I% [2 {  document.sform1.email.focus();     , v! ~2 S1 q7 d# t- o: W$ X$ O2 ?
  return false;       I7 ?1 c3 K2 n  k' K: I5 V* e% T
  }           3 l, H* R. V& f  Z
  % m! _" D! Q* P& i, t7 X
if (document.sform1.checkask.value=="") 1 n8 L3 q4 M9 J, F9 f" ^( A. e6 j! q; r
  {
0 E8 k+ G! w2 v  u* `   alert("密码提示问题不能为空");     
( m( w8 p9 W7 {4 T' N7 L$ i   document.sform1.checkask.focus();     / n4 Z4 y# z8 U0 P
   return false;  : m: u' f4 m; F1 g
  }
1 C% l6 @* a- l' { if (document.sform1.checkans.value=="") $ a" q$ v- N" q2 b# F5 Z
  {
! H* F+ B' w4 R/ \9 D4 y- x% R   alert("您的密码提示问题答案不能为空"); # `8 |& d9 N3 i1 k! q9 V
   document.sform1.checkans.focus();     ; W, i+ t4 o+ ?$ K' n8 R/ U% B; }; E
   return false;  & o6 K7 p# Y8 b" e
  }
& U0 Y8 e7 {* J/ ?. @2 T0 L: ]3 M return true;     
' T: r; G' o% H1 @" P     3 Z6 j  a7 p% J$ E2 E
}
' |0 G1 q* j6 }0 v3 B6 Q</script>

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