返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:+ A3 c5 t- W: T8 ~" z4 z
<script language="javascript">     
) Z: ~/ G) r( J" x% o: Ffunction IsDigit(cCheck)     
- B$ Q& i" N, b8 Z5 N {     
* ^2 ?$ g+ X2 o return (('0'<=cCheck) && (cCheck<='9'));     ! f2 K) d, ~, W4 ^6 q. C: p
}     
& f! A" V! c' B: V- G     
  _" r( c; R0 ?+ Z; Y4 N5 kfunction IsAlpha(cCheck)     1 ^, m5 K, j. V6 J
{     
& q* \0 Y) `+ p" N return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     5 h$ }6 }9 v0 k& S- ]$ K. N8 ~
}              $ o" [; n/ B8 R- S, e  [: D+ ~" s
      / i. h' I5 N% Z8 w  q. W
function IsaNull(cCheck)          5 V2 U5 X8 s9 I
{         
6 V8 h3 X. O1 n) {# U return(cCheck != " ")         ! D+ H/ L4 ]8 B" S. g8 A& A" s$ m: |7 `
}                               # ]2 l% u4 _# k. n; X; N
      + {  H+ e. G4 O2 e; E
function checkform()     / t( w% {# s; a& x
{
3 O5 l& a3 V, E# \; S6 t  id = document.sform1.id.value;     
+ f1 o! @& ^+ V) U  F: @7 ^' c2 K9 M if (id == "")     1 c# }4 _4 ]. m4 P0 i# O6 @
  {     
; m  `; M: t1 E" o- r8 Q# y  alert("请输入注册名");     
; b7 I3 a2 U3 _  document.sform1.id.focus();     0 K4 {7 v' a7 M9 f
  return false;     
, V2 |5 ?' U( |' ^  }     
2 V% b, k0 _! {% n8 @     3 W. X! x! d0 }8 a5 ]6 o
for (nIndex=0; nIndex<id.length; nIndex++)     
7 v8 `. e. b: c/ a! R9 ^4 S, Q( |  {     
, h6 T1 L. Q. q4 U- J  cCheck = id.charAt(nIndex);     
% |& J( |4 z) R) }4 f0 }/ X  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
! E& x1 {) c* K. _   {     9 r, v7 i; O) M0 D
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ! {5 I3 V% Q% q& |! w
   document.sform1.id.focus();     
) C  o# @& a+ O. v* I* J" p   return false;     
$ h3 n  ^" C3 S: V  }   }     
9 D5 m* C4 |6 P  _) b  }
% X9 ?3 C+ A" S  chineseid = document.sform1.chineseid.value;     ! Y$ z) H# o: B0 d+ s! G
if (chineseid == "")     
% y. Z4 a# E. i8 C! M! Q  {     $ N- H3 H; ^: s# A5 Y7 M
  alert("请输入中文昵称");     
' S% R- A  j* }9 T/ R. _  document.sform1.chineseid.focus();     * p$ V2 m/ g: h
  return false;       ~  `0 Z' c/ E
  }   
! Q' |( v9 N+ M7 n2 @/ [ password = document.sform1.password.value;     5 p: m7 e3 ?! D; ?
if (password == "")     ! ]1 {" _# R6 g6 S- X" @
  {     " y% r8 h" s9 b0 W, `% k& S- Z% d
  alert("请输入登陆密码");     , c; x7 D4 d+ C/ ?+ A8 k
  document.sform1.password.focus();     9 z- r6 Z' e: U
  return false;     9 J8 p1 n; L3 x6 G) Z6 C
  }
* ^2 R; D1 j0 t8 n, _1 H password1 = document.sform1.password1.value;     
* ^6 d2 _# G- o0 e# C if (password>password1)     
& w- s& v1 `% B0 G* b  {  @$ p" i2 `! h' W4 K
     alert("重复密码与登陆密码不相同");     
& t; b' g1 ?: U( h/ q. u' h  document.sform1.password.focus();
# H9 h7 t& }) K) i; }% Q( N                                document.sform1.password1.focus();     * o5 ]3 @% _8 {/ i
  return false;! K1 y1 |. i4 u
  }    N4 D4 k( E9 n. O* k5 w
if (password<password1)     * p4 G* S. ~$ Q
  {
7 V( P) ~* T) q$ w: y2 ?     alert("重复密码与登陆密码不相同");     ( g# t/ D4 I0 @
  document.sform1.password.focus(); + D0 R: B7 _5 Z' t, P0 P4 c$ j
                                document.sform1.password1.focus();     
4 q) u4 c. h8 G% F  return false;. `# x) J" e0 B- U
  }
8 R  P+ s/ z8 |& h4 o7 D: s if (document.sform1.email.value == "")     ' Y& j2 ~5 F, p6 a8 K
  {     
& p# O7 n5 @! a$ c# z6 g4 S2 \  alert("请输入您的E-MAIL地址");     ' G. F9 E$ G. H! t1 }( I
  document.sform1.email.focus();     
2 U' w+ y7 q8 o- z  return false;     
& j3 G) x8 z! j  }     
' ~8 [3 W+ N3 K" }3 J      
8 ~/ y9 f4 S9 e3 V3 y* ~, f email=document.sform1.email.value;      
7 u, u. M! r" {  X" K) \ emailerr=0     
. ^+ _7 C4 n" A6 R for (i=0; i<email.length; i++)     
% t7 f1 t. ^4 T; z5 _  {     0 i1 Y/ [; \" H) k* E
  if ((email.charAt(i) == "@") & (email.length > 5))     
5 r! }$ r2 M7 ?   {     7 M! x' `2 k9 {; u% v
     emailerr=emailerr+1     % W  p# k; Z! P3 n9 c
   }     & R% Y( o) J( n
  }     ! ?2 P" u, A0 K8 ~( P
if (emailerr != 1)     
4 T$ I1 D1 |* C( C8 b- v) ^  {     - @2 U3 I* X- J9 c9 L5 h
  alert("请输入正确的E-MAIL地址");     
% m% m% Y" [" h0 c0 e! V1 |  document.sform1.email.focus();     3 G8 m1 @; V! S0 Z
  return false;     
: O; }3 j  r' u3 e, Y7 q; f; q  }           
! I+ `2 ~2 g0 y: a0 f  
# l2 e' S5 n* [/ U! ?8 j if (document.sform1.checkask.value=="") 8 O4 w5 Q# F$ K: \6 G
  {
, T; i! S, b( n! E9 }2 i5 z   alert("密码提示问题不能为空");     
! j4 O% L% I7 t7 G/ j   document.sform1.checkask.focus();     
* s4 w& y6 _" o2 r   return false;  + @3 ~2 b0 R9 R4 m. ^' Q
  }
( f9 j4 n' g9 Y: u if (document.sform1.checkans.value=="") / ]% E8 u5 \+ w/ i
  { 3 W2 [! T" x* {9 J6 F# y+ p
   alert("您的密码提示问题答案不能为空");
3 k$ L9 _! V9 L& e   document.sform1.checkans.focus();     " |$ e/ u9 t2 T; l
   return false;  
. x' X1 R- X- a9 [  }4 N( m0 |# d% m7 y* Y( m
return true;     7 Q7 y) F1 M( i8 f
     
' r% C. d1 u8 d+ Y4 b} - n9 x  X; @& G, v
</script>

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