返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
0 ?7 Q* F. l1 _1 `<script language="javascript">     4 w; h& s" j+ z4 t
function IsDigit(cCheck)     
. p) d) N0 n2 ]; N; C {     
8 L; l8 E8 X# g& z9 j8 w- | return (('0'<=cCheck) && (cCheck<='9'));     
% v  H. P$ u* L) H2 c }     / ~2 C6 V8 L, |  i& k5 D) `
     + C* g8 S1 \' y7 J5 n$ b
function IsAlpha(cCheck)     2 b8 f' {3 R0 a
{     
  {: }) d' o( ?5 w" ]3 { return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
& N7 F0 {8 a8 w  r+ R }              2 m5 L- j3 x9 s, ]7 h
      ; ~1 \% g% n) H1 B
function IsaNull(cCheck)         
# f' u4 p. L* _ {          * A5 T' Y( C- e
return(cCheck != " ")         
8 \& ~; E' U: i, n }                               7 p( i4 ]' I! ~) z9 T3 L3 o
      
. t. [& j% E6 w5 Z* dfunction checkform()     3 u# D5 ~9 d& K: A9 W
{
3 m5 Q  i9 n/ a  id = document.sform1.id.value;     
$ v3 ?: `5 J6 H) }9 K, _ if (id == "")     8 }% @! V- l. g. P/ {
  {     2 s: l7 N- @2 d5 Z  W
  alert("请输入注册名");     
9 ^: `6 }. n" n) S  document.sform1.id.focus();     
9 \9 V! e- E( {. B  return false;     
0 z+ O( @* L& F1 V0 j! \$ G  }     
: y' l7 G. @* R# H* n     
4 [% D: t; \) t# J- M for (nIndex=0; nIndex<id.length; nIndex++)     : ~; E+ [* ?5 D" N0 @6 S8 M
  {     4 R( h4 k( Z$ I# _# Z. y6 w
  cCheck = id.charAt(nIndex);     
: S: ~; X8 _; S  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
( G" u1 u8 Y4 q8 u+ n   {     : C" S) n' H1 o' c( \1 r
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     2 s( P3 ?; q- I  o( S' [! f& _( c
   document.sform1.id.focus();     2 j7 X% q5 q+ T* Z  t( V
   return false;     
0 |* M, D/ _! s7 s/ Q   }     
! M" B! I( H$ r, _) C  }
2 S% `7 ?8 e0 T* r% E, c' w  chineseid = document.sform1.chineseid.value;     . ]) e( [2 G0 O; n
if (chineseid == "")     
* ?8 C8 h: p8 J( T. |! O2 ?  {     
' u4 n% Q6 m0 n) E6 [+ r$ D  alert("请输入中文昵称");     
. K0 Q, T+ g/ F# Q+ x4 o  document.sform1.chineseid.focus();     
8 v' e- T2 c) W, E  return false;     
: Z- a& h, ?7 D# f1 ^  }    2 r/ h% |4 Y; ?, x1 ~
password = document.sform1.password.value;     
0 }' i: a( _! N- }! t! |4 [ if (password == "")     
  X9 F- I) A" p8 S% d3 `6 W8 c  {     
, {9 j* ~. I/ V6 K# s) e9 ^  alert("请输入登陆密码");     
4 U; ~" Y+ x6 q- p% l% b4 k3 b  document.sform1.password.focus();     % u' y. D3 G0 `: J0 e$ _2 v' u
  return false;     
8 y9 h, i  W. @  }
- k; p0 L- M- _, k" A" U& b password1 = document.sform1.password1.value;     
- X' g8 l; `* P& |+ p2 h if (password>password1)     
% K0 M9 j4 t7 n, g  {  w4 ?, h- U. j+ e# P9 d; U1 H& W, @
     alert("重复密码与登陆密码不相同");     ( b& d: O9 q' t" h3 J
  document.sform1.password.focus();
! k: j  @+ j- q, {6 n' V5 ?' V) D                                document.sform1.password1.focus();     
" ]: {: Q7 ?. X0 O- ~9 p  return false;7 {& S  x) r+ @9 S3 n/ ^: y% |7 D
  }  
& z& I1 {0 O7 c+ ]. Rif (password<password1)     * x" I  D1 G2 s* T
  {
8 T1 R9 c9 L" u; h+ Y     alert("重复密码与登陆密码不相同");     
% _# c' e! ^- [8 h  document.sform1.password.focus(); 4 L! B; H, S$ G" f. `9 Z
                                document.sform1.password1.focus();     
) I3 K( ?( o7 ~9 k% R- [0 X( j  return false;
* ]+ n9 t; q% N# N7 O: ]8 q  }
' @8 ~% `1 b- s- T, G, K: \ if (document.sform1.email.value == "")     ) Y1 g/ c5 X2 G5 R
  {     / q/ O) {. _* D$ t/ I2 B
  alert("请输入您的E-MAIL地址");     " l8 o- Q$ B7 e* Q: Q) x  I: S
  document.sform1.email.focus();     
2 n$ h5 |7 j8 q7 i& z1 n5 n  return false;     ' ~1 S! O- z; x
  }       a, C5 A0 W, J3 Y) s
      - o  ^* C" j! \  z
email=document.sform1.email.value;      
1 X4 \7 O! a0 r, B, w( T2 i emailerr=0     
& I5 U4 A3 S; |$ f+ A8 `& c for (i=0; i<email.length; i++)     
& L0 N# A  T& u$ ~0 W  {     3 I% u6 y' r9 \9 S0 P" Y% y1 s
  if ((email.charAt(i) == "@") & (email.length > 5))     6 C: i1 ~; T4 `" y. p+ i; g& l0 B
   {     / f! A) `) T+ h0 x
     emailerr=emailerr+1     % S# |4 D7 w+ O! B
   }     
$ L1 n/ R! d/ i% f5 M! r  }     & V; ~6 G& @- q$ L
if (emailerr != 1)     ; t1 m; c" A7 |
  {     
4 P) K* u1 t+ @, e) b! \  alert("请输入正确的E-MAIL地址");     : J3 ?4 h5 }% i  A
  document.sform1.email.focus();     
8 e% t; ?% g6 g# K# z! w' G/ H  return false;     
4 P# d0 I+ L3 o  }           
1 @# O  ?. c: ~" `; D7 E  $ y) i+ \3 s' c+ N/ X' L
if (document.sform1.checkask.value=="")
3 W  P% y4 N/ L2 F' I  { ) f# W  I3 P2 `, z$ n* [
   alert("密码提示问题不能为空");     
: K& L7 U, I) A% C   document.sform1.checkask.focus();     
$ ]. b  k8 z2 l   return false;  # r5 ?$ m& A+ t' P6 _
  }
) k- m8 p* v  P$ I if (document.sform1.checkans.value=="") 2 d8 j  c! M8 \1 _
  {
- w- A& w! x1 {2 d  U6 H" g2 Z: Y' R0 Q   alert("您的密码提示问题答案不能为空");
  _% G1 }# n3 T2 P   document.sform1.checkans.focus();     0 n" {, @% I8 |0 H8 |
   return false;  
' ?2 a/ X: F/ L* N" {) T) C% _/ P1 w  }
+ M, M  A+ G5 `# X' r return true;     
8 b2 `, N3 q4 O1 S/ c, l# y     % d2 d2 P; ?/ k  L3 Q, K& [/ u
} 2 x; E- p0 F* K) J: R. {
</script>

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