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

一个注册表单验证的js

这个脚本对你可能有帮助:: K; a3 Y! \( B) h/ @  X, ?" b
<script language="javascript">     
. T( _9 J7 N- ?! x4 E$ wfunction IsDigit(cCheck)     
( g' z: p) Y1 r8 d# ]) P+ [+ B {     % ]; m. s- i; v
return (('0'<=cCheck) && (cCheck<='9'));     " n! e3 e; i* \( T
}     
0 l; L1 y9 l& s, H8 Y3 d; i- S     
- [7 G6 C  _" G  [* Kfunction IsAlpha(cCheck)     
' [1 z( K7 t" l6 j/ R+ o' @ {     
. P) x7 M- Y, }* p2 H% R6 F return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ! @5 I, }- B; p; E/ M
}              
# x! u, P9 ^  S; B5 j# t! W" M8 G      # Q' q9 c# |7 A/ `- w
function IsaNull(cCheck)         
+ F2 X0 W; |8 W) h0 m/ {* @) t {         
" H. ^: r$ {$ s, h* h$ q* c return(cCheck != " ")         & I8 P* {* v' o! R% s' w
}                              
+ g* Y1 K, c. i# Z      # A6 _: V" f' R8 I/ S
function checkform()     
- X% ?# W9 [9 }* ]. J{
3 ]7 `  A, s; o4 l1 f  id = document.sform1.id.value;     
# S" |) P0 ~  I* y% K# |5 z if (id == "")     ( s3 G  q6 K" z/ S
  {     
1 p' `  {  j1 [4 e  alert("请输入注册名");     
9 w! U0 p6 K* s+ U  document.sform1.id.focus();     
, ~$ L5 c1 e* n1 v0 W( r& L  return false;     # p* q( H) z+ c( v3 I/ D2 q2 {
  }     
' D2 t* a6 f3 [. Y1 d     , {8 t; C' T  Q3 m$ r
for (nIndex=0; nIndex<id.length; nIndex++)     
9 x' j* [; G' ~; f6 T. ^  {     ( U" P7 X0 K& a
  cCheck = id.charAt(nIndex);     
* Z& s0 V& Z" e5 N, ?  x  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
& Y5 r9 f9 Z9 x; h+ `8 f" |   {     # I% E' E& E& F
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
' K  f. O0 p& j6 q- o, b' R- D   document.sform1.id.focus();     
# B& H! Q0 M4 p* v; k   return false;     
$ h+ V" ~* m( C   }       X4 [  _- {0 _0 e3 b4 Z- }" c9 ^
  }
  F6 S/ P' D# \/ b/ K2 E- L4 X3 `  chineseid = document.sform1.chineseid.value;     / I, P1 G  t- V
if (chineseid == "")     # [& d' _& ~7 c! C9 b
  {     
) n; c% N- W4 ]  `2 L3 E0 g  alert("请输入中文昵称");       ^. {/ M7 p- N/ L
  document.sform1.chineseid.focus();     ( C, `# ]* O# f4 j* {6 L8 Y: \. u
  return false;     & L9 \( v5 x3 t% ^3 l4 F' P! E
  }   
( m8 b2 F' G  S  Y1 D password = document.sform1.password.value;     : u( g- j( [5 Q4 t# K# L$ ~
if (password == "")     
9 K$ B" `: d% b7 f8 g  {     
$ \' M2 s9 e/ W, T- b2 D  alert("请输入登陆密码");     " b/ b+ ~0 C& ~0 F. m" Z
  document.sform1.password.focus();     
! N& T* B5 D2 C  G4 ]; H  return false;     6 D1 w$ _: i0 [0 h0 f) h
  } * q" }! U& c) W* e# l) k
password1 = document.sform1.password1.value;     ( K: m* ~3 z/ w) p7 {. Q7 S6 `; E
if (password>password1)     
& c9 ?5 S! M1 z( p  {. o* ~3 L# N, ?, Y1 z; R! d2 ^  A7 ]  F
     alert("重复密码与登陆密码不相同");     7 z! R/ w7 }+ ^( Q5 }7 ^2 o5 b
  document.sform1.password.focus();
1 k9 ^$ R" x* C, A* g                                document.sform1.password1.focus();     + R/ `% q( M2 ?# q% \
  return false;7 H# Y, b$ i5 J! W; X) T8 Y$ Q
  }  
9 @$ S% f4 r/ xif (password<password1)     
6 K: V2 Q; A. p0 _9 x9 L* f  {
; Z% O% [7 V% r5 ^% X# w     alert("重复密码与登陆密码不相同");     : _( ]& w0 [" P4 u
  document.sform1.password.focus(); 5 c/ x: W+ J0 `8 }- i9 w6 r7 N
                                document.sform1.password1.focus();     , ]4 q; \4 d& R6 P0 v/ ]- Q
  return false;
  i3 q& R3 D6 {  } " v" X, j5 A( L4 i$ d: [
if (document.sform1.email.value == "")     
. {2 E( n  S, Q* r: X  {     & [6 C+ T( Z1 w; x
  alert("请输入您的E-MAIL地址");     
% U- s9 U3 x" q5 a7 i  document.sform1.email.focus();     
2 P! E& J. a, }9 W3 \3 n/ [  return false;     
9 o; v0 i/ ?9 D( h  }     
; Z% X2 U# z! s* g& }! Z6 d/ y      * s  S4 Q1 ?# a: {- Q
email=document.sform1.email.value;      7 w* ~/ E. `+ q
emailerr=0     
0 ^5 A2 F4 c" X& t3 B4 x for (i=0; i<email.length; i++)     5 y2 e3 E% ?/ @# S
  {     5 ~, C5 v/ |: H( h# _
  if ((email.charAt(i) == "@") & (email.length > 5))     
% U, t, L. e/ `6 P   {     
- C* j$ H$ r* g' w1 C4 [6 H     emailerr=emailerr+1     , E6 f5 N1 j! g: I
   }     * ?% e) \6 |" ~( M7 P
  }     
4 P, M. {5 {+ j  M if (emailerr != 1)     
6 I8 e2 E+ Z! @2 Z: h& D  {     : z' z) t4 s8 t5 x) m8 B' y
  alert("请输入正确的E-MAIL地址");     
) I9 V2 `) m4 s% k' W2 L  document.sform1.email.focus();     
8 |. G: W6 \: j3 L) y% u  return false;     
4 I; L% O9 a& l7 U: `  L6 r$ s& j  }           
' S  Q& l" M8 g4 o; ^0 T5 h4 D  
: ]" H3 ^) ?3 i; B% l3 }  K if (document.sform1.checkask.value=="")
- k# m+ ^2 Q  U4 d- V3 N  { ' C- }7 a( u' r- A+ |/ |; f
   alert("密码提示问题不能为空");     
+ Q  ]7 ]$ B" e" {   document.sform1.checkask.focus();     ( q$ F* z: D) n2 U& q4 n
   return false;  
' I1 u7 }% `% i- n$ u9 j. s  } - ^8 z6 W  ]4 V3 h) F/ s0 w7 I
if (document.sform1.checkans.value=="")
4 q1 C; O+ F/ N  j, `5 }  { ( G- D$ N% J) L
   alert("您的密码提示问题答案不能为空"); 8 C3 r# I" j8 x7 c5 a( Y
   document.sform1.checkans.focus();     
2 \" I* R& S% T" s/ q/ N   return false;  
9 W" E$ A( D+ o- F% I0 Y  }3 }3 J" M- N8 F( O
return true;     % I3 p1 L" r& u0 f
     
; D5 E: U, C" ]8 b6 U4 B}
- F6 @7 {% \; G6 I! f</script>

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