返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:: \5 j2 r! y/ c5 j/ u  W
<script language="javascript">     ' l* y3 W% F3 H
function IsDigit(cCheck)     
) n' d4 D3 u/ q {     
; u0 ?3 `4 |/ P' U& y/ _4 m( c% e* L# c return (('0'<=cCheck) && (cCheck<='9'));     
: L7 P5 a- @# ^) I4 D5 h }     ; M$ v3 h/ y' C* \
     ( d: r! S; J& g8 E/ B, O! G7 G' S6 x
function IsAlpha(cCheck)     . ]7 ^* ]( V. b
{     4 p! _% T7 L* a9 t  D0 H( b
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ' u3 Z$ X1 D0 z  |8 ^
}              . t" p. }0 l8 |$ \* L+ `1 ?6 h' j+ A) t
      
* b# h! [8 g& B/ t- ffunction IsaNull(cCheck)         
& O8 q, z, ]- r {         
: G* J7 k! ^+ z9 I return(cCheck != " ")         / L; g( l8 X( ]8 l7 L3 {
}                               / z$ n3 W5 g. Y2 U3 t
      ) M; t' R6 h0 m9 W- r% Z# R6 |
function checkform()     " F2 d9 E% l+ v! s- u7 m5 ~
{ : a7 q5 W( e' w
  id = document.sform1.id.value;     
' n' A! G) T. X9 j# q# ` if (id == "")     # l9 X2 p- M! |" k1 ^- f, I
  {     - e! x: P& c# J$ W
  alert("请输入注册名");     
+ N; D, s  ?2 b+ n$ s2 O0 \8 V4 ~' F  document.sform1.id.focus();     
5 l& c/ ?; W: H4 V. ?/ N  return false;     
6 ^, o  U& k2 U) {2 m  }     ( m6 \! R5 v- d: D; H( s% S
     # f# J( O) S- ?4 i2 I5 m
for (nIndex=0; nIndex<id.length; nIndex++)     
7 ]9 R3 G+ z4 j3 V5 [8 U7 B. w  {     ' h' ^3 L/ @: B$ }  s( Y' a6 m/ T
  cCheck = id.charAt(nIndex);     / x/ [& o& b! o8 d* m; @
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
0 W- A3 j& f5 {! z. m) Q   {     
4 s4 c2 X: O( @* B! n% r6 P   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
& `, O3 f/ \' {9 s   document.sform1.id.focus();     - Q+ A+ b' c" s3 w1 P
   return false;     7 m2 L8 {& C% H  X
   }     
" I" C2 g/ h; o' t% [1 R  }
) U& L  {5 r  o$ t; @, F* W  chineseid = document.sform1.chineseid.value;     1 W+ @5 a' `- P) Y
if (chineseid == "")     ( _& }7 i# `, `0 c* D& x# M
  {     
; Z+ A: X( v# T6 g8 z4 c( F  alert("请输入中文昵称");     
0 x! h1 z3 D& b% f3 k1 r5 {  document.sform1.chineseid.focus();     
" s8 u0 m- C( x" ~  return false;     
8 b$ |9 N4 O( _  }   
6 u* r% d1 R: F6 Y- l5 u+ l- k password = document.sform1.password.value;     & S! k: F5 x% a9 B. n( M
if (password == "")     
4 ~( Z0 W# y( c( S4 Z  {     
* r" D" B5 q0 K  alert("请输入登陆密码");     : Y- C2 t; u  M: f% S) k5 }4 j# \# x
  document.sform1.password.focus();     
, A; Z( d% A' T6 Y3 W0 P8 f  return false;     
/ _! k0 P% n) `6 A8 A# L8 `  }
2 {' I0 _  G, A$ @ password1 = document.sform1.password1.value;     
% R5 H2 G) k0 R6 u if (password>password1)     
; a8 {6 p1 i: l$ S' U6 H; y- S( Y8 k' s7 e  {
  J/ n7 d. M  m- d  j9 [     alert("重复密码与登陆密码不相同");     
% D! u; R( m% l7 C9 j  document.sform1.password.focus(); # ~) @& g. X) C3 A" U% p
                                document.sform1.password1.focus();     ' V3 S' y! s1 y1 m! x3 J4 Z2 t
  return false;
5 G, h* O! M5 O5 _* v" P  }  
+ {; A1 a; a2 v1 m2 k: Cif (password<password1)     
% N, Q  F9 Y$ I+ [8 O  {
( T) q8 i' w) Z6 }/ f     alert("重复密码与登陆密码不相同");     4 |. l2 v, l3 N8 {
  document.sform1.password.focus();
' a0 o  w( F1 ~4 S5 l                                document.sform1.password1.focus();     
5 \4 F& I, h5 I0 ?) m  return false;6 P9 Z( n. g" W) ^
  }
' S6 Q/ f0 `4 ]' U1 J! t; L if (document.sform1.email.value == "")     
* M0 o" ^2 D+ m6 ^  {     
5 b/ V( O1 k8 x3 v. k  alert("请输入您的E-MAIL地址");     
3 f/ `( S# G8 T  document.sform1.email.focus();     9 z8 j0 G  H# y- r4 K( n9 \, C
  return false;     7 R+ [3 B+ {1 q; `
  }     
( A9 W5 z/ i7 j      
* @; d7 E! s* H email=document.sform1.email.value;      9 M. l% G" @$ v) B* G
emailerr=0     
# g" \( [$ M7 Z. z' n for (i=0; i<email.length; i++)     ' t, T9 R% K6 r& B/ n. s) s
  {     
% y% P, R% b4 y3 C8 ^' \  if ((email.charAt(i) == "@") & (email.length > 5))     
/ w8 a2 Y0 K4 @+ D% R   {     
& H( f0 _/ I5 v( s+ d     emailerr=emailerr+1     
& L, c; S* t. T! P0 A% D) K   }     & B; U3 y  j, h+ x
  }     + R# K& ^- ], [* p" F' T
if (emailerr != 1)     # X! i6 z4 U2 y: c# X
  {     , a! H3 a, O" w
  alert("请输入正确的E-MAIL地址");     / ]6 g1 s( [8 O4 |& ^8 s# y
  document.sform1.email.focus();     
  c. f0 ?- Y! \4 j  return false;     
- b  A# S* q+ s2 i" H  }           , o8 [0 Q) W5 q6 K5 m' R* t
  ' R; N. z! c; Z
if (document.sform1.checkask.value=="") , z2 g" m6 T* V
  {
: _  F4 @) F- h6 ?% x   alert("密码提示问题不能为空");     : h) M0 z8 V2 @0 Q
   document.sform1.checkask.focus();     
  r5 _6 B; r* J   return false;  
3 p, N9 k: g! @' a, w1 {) S  }
7 I3 c) z5 E( L; [7 F if (document.sform1.checkans.value=="")
- J6 T" z" ^2 n% _6 Y, I6 Z  { ; |# n; |; Q7 G3 X9 \7 s( f" V' C
   alert("您的密码提示问题答案不能为空");
, q& M$ p* N) H7 V   document.sform1.checkans.focus();     
- N+ x: R# p9 B% @4 G+ L$ F' v* t   return false;  
9 M: R5 Y4 v# S* f, P  }, ]0 `3 E3 ]1 w+ @
return true;     
/ |! Y7 [) j( s' v6 {: f( q' J     
% B0 Q% O% L1 n' W1 a* M: e}
5 A  b% ~0 [0 y' d; f8 h0 |8 j</script>

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