返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
5 I) u$ g" t8 Y8 \; G* [! v<script language="javascript">     3 [4 e2 j( B7 r4 O- L
function IsDigit(cCheck)     
2 h, c' Q8 w, \% [( f9 W/ H {     
3 h: L/ |0 n( d  L; d  W$ C  L7 E' Q return (('0'<=cCheck) && (cCheck<='9'));     5 c7 ^4 [3 _7 A9 [  g
}     7 K9 q5 C; u# u" t1 s4 i- |
     , m9 y0 g4 C: V- ?) J0 r
function IsAlpha(cCheck)     . I: j$ ]2 f% M1 Z7 o% f+ f. @" G
{     9 G. s$ g1 H% U) e
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     0 w/ t0 j; q" S# D% G* n# f) y4 D
}              
5 r' I8 o3 Y+ r) q/ L      
/ E' ^3 p' A9 f; ]5 o1 I+ }, n, j+ dfunction IsaNull(cCheck)         
) [4 v; T! \/ n* T8 [) b# B {          6 t+ h" e8 M+ }& V; [
return(cCheck != " ")         4 l! O/ w, B. D# \( Z/ `, n
}                              
: M' j8 _. i  `8 J. S; }' ^( C      
! x; a9 e6 Q; Nfunction checkform()     + ?9 p9 f" t5 A4 P! g0 _* N. b
{ ( c4 n- [7 F8 L) t' w" x, z; x
  id = document.sform1.id.value;     , Q3 h" P7 [4 s4 G9 K5 @
if (id == "")     
  G$ c/ p3 z" i4 a, R1 r3 f  {     
+ d1 V* _6 z0 S$ t2 Q5 s7 W6 m/ s! u  alert("请输入注册名");     / M. x% I+ v+ O% ?9 f  x
  document.sform1.id.focus();     $ D. x! E" Q: G5 z5 `( a
  return false;     
1 z7 p3 o6 I7 a  }     & _) y: Z5 m6 ^% ], [9 b  t% p
     
1 F) J) k2 d( ]! I% e  { for (nIndex=0; nIndex<id.length; nIndex++)     
& c. g. X3 D* M3 r  c* B& d1 j  {     
0 W# v% O% j+ ^% Q/ V" T: M  cCheck = id.charAt(nIndex);     9 Z, i- K7 G3 c: ?# h  k8 o9 \
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ' z) S  o1 P3 N5 ?" y
   {     
  ]* G: e- t7 q/ W* ^   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
6 p! W3 \9 z( ~3 @' _( z* C   document.sform1.id.focus();     1 L8 B/ T9 M  G6 e5 @: S
   return false;     
$ o1 B3 G# P$ w3 S( b( t   }     
5 O" v1 C- I! _7 C  }
+ d% K0 v& l- Y/ c; K5 |) o% S  chineseid = document.sform1.chineseid.value;     
- C9 Z, y6 B4 y7 ^$ }) _8 ] if (chineseid == "")     2 z6 \! A- ~; B* R4 U
  {     
+ Y7 P8 o- c) b7 w/ b0 V  alert("请输入中文昵称");     ) j4 O" p1 ^( A" m3 u- D9 z
  document.sform1.chineseid.focus();     ) W2 }. h* H8 g# D; ?2 p+ |
  return false;     
$ v; p# c" I/ r+ o; W9 R0 [( v* q  }   
, L* r- Y2 I6 ?: f& ?0 H password = document.sform1.password.value;     
  J, Q* A6 M& `$ z- X( C if (password == "")     
+ s" R! f. q  O  {     ' b2 n! r$ _/ F# H
  alert("请输入登陆密码");     
* _) W! O( Z0 u! f  document.sform1.password.focus();     ; x1 q6 ~, [+ P! m7 ^% ~
  return false;     9 |0 E+ u" O2 R$ H# B4 r
  } 4 C) X2 n! R* }, C; r/ s5 H
password1 = document.sform1.password1.value;     % i$ f  l1 @  i) c4 w; i4 P! K
if (password>password1)     
' R  N0 N7 O% r# C  {5 h. {4 Y8 C6 r6 J" |
     alert("重复密码与登陆密码不相同");     
  j$ o# n9 }9 D7 x& \3 K  document.sform1.password.focus();
- d1 {0 |" H- t. e$ M4 y                                document.sform1.password1.focus();     $ b# Y2 f7 |3 a9 C" F! c' u
  return false;8 l' d5 ~1 D- E0 G
  }  
' `% k6 e& `- c3 Eif (password<password1)     
2 z& X4 V, ]. P  {
' h# J" l( Y* {) |( ?, ~     alert("重复密码与登陆密码不相同");     8 f# i! q5 f' A6 v! G/ U
  document.sform1.password.focus();   [; z- r- M: t
                                document.sform1.password1.focus();     : ^2 p2 j) ]+ j# c: V
  return false;- ]9 J* b% `0 `9 }, d7 y! E# G
  } 3 X6 s5 u+ A5 S
if (document.sform1.email.value == "")     $ R7 p& o0 e) A! d
  {     
( p( @3 i% ~! U  alert("请输入您的E-MAIL地址");     $ ?$ h0 H" w+ \% E; O3 G1 c+ v6 K: P
  document.sform1.email.focus();     ( ?4 g5 `2 v+ M  n. D# a( E
  return false;     
/ ^$ B  X; f) t: P# u1 ?1 x0 w  }     / V6 Z& L, s1 x3 S
      
! d2 I/ r" V2 R! T2 k email=document.sform1.email.value;      0 H$ [" b8 Q3 I
emailerr=0     
) Q) z. r, _" U7 L' Y6 R0 X for (i=0; i<email.length; i++)     
5 p( e% i% M& l% T  {     
5 ~2 K7 b9 ?/ P+ }% A  if ((email.charAt(i) == "@") & (email.length > 5))     
* P( \( V0 R8 D8 L; J2 F   {     7 n% p7 v) j6 U, }  t' v/ ~$ y  N( b
     emailerr=emailerr+1     
) Q& S+ \7 P, d1 o- R   }     " a, u% @4 g, L# x
  }     
1 B. a, U3 \4 a+ n  p8 ~ if (emailerr != 1)     # h" \" P! K* p5 S; \. r% X2 y# A
  {     & z" E) a$ y! J$ O- ?2 t
  alert("请输入正确的E-MAIL地址");     
" E8 [% Q: h: J9 R  document.sform1.email.focus();     . O6 P* [5 ~, ~5 R. v" E; M$ }
  return false;       m+ ]9 X! h, L. i/ \/ K- d! M
  }           
) S( o, g9 H; R4 S6 E; j  ) `5 n  L- t7 `. q/ w9 l/ F( _
if (document.sform1.checkask.value=="")
7 n( m; Q/ }  V. w) y, ~  {
: Y- L4 l/ R  w0 Q; C: l   alert("密码提示问题不能为空");     0 o2 i& M5 M3 N2 K
   document.sform1.checkask.focus();     % n8 q2 F$ N8 O) I. Z& D
   return false;  * }2 g) ~/ P$ W4 h$ Q  |/ G+ q
  }
5 I" L4 _8 x0 _ if (document.sform1.checkans.value=="") , c  Q/ O$ P1 s# D
  { / [7 r5 |& }8 ~9 V4 i  {9 e
   alert("您的密码提示问题答案不能为空");
- {( }+ L+ d2 f   document.sform1.checkans.focus();     * D, ~; _- ?9 h" t( a
   return false;  * y) Y, M6 c) z4 d6 w# K+ I8 n2 p
  }/ b5 x$ p( [4 |. C9 {! a+ |
return true;     ' q! x) U, e  k1 ]& f2 h5 r1 ]1 a
     
# W. T4 Q5 O' \- x}
: m' h. m9 }% v1 H; L# J4 j7 w</script>

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