返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
+ F: T4 ]0 f* Q* Z1 h<script language="javascript">     " `4 [6 x# h% I
function IsDigit(cCheck)     % l* b9 d4 _) q' Y6 e5 D
{     5 F/ v$ ?! v2 p4 Q- I# U7 }
return (('0'<=cCheck) && (cCheck<='9'));     ( y: u" M. c% G8 s! \1 Y' f( }
}     
: @: C6 X* z9 {9 X3 n# Z     ( p6 k* P, H2 V0 v! Z4 `% n
function IsAlpha(cCheck)     - _5 _1 |7 P) x9 ~' [, |$ G
{     
/ x9 u- H7 g: `: i6 E: [ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
% \  i- j4 p1 v. V, i! ` }              
0 T+ c/ w* _. o1 a) B$ C      / K+ U3 \  ^0 g' E, v7 ?0 I
function IsaNull(cCheck)          & r1 v# i8 [4 b& J9 |: S/ m( U( r
{         
" F! y, G; [9 O, B# F* ~- q: g$ D return(cCheck != " ")         3 N! t& }8 w9 N: K6 ?# z1 P9 U
}                              
1 D6 ^% E7 ?7 a+ @+ C& G1 H  f, g8 r      
; q- w5 f" c1 f0 ~( v* [# l2 Wfunction checkform()     ) a! h0 E' a6 c! S8 o# E  O' N6 M: U% k* U5 P
{
8 e7 S0 W4 Z; Q/ V$ t0 |" [  id = document.sform1.id.value;     & V, G4 Q! K" q5 E' q
if (id == "")     
/ T: {; J% [  ~! u$ N* a! P6 Y+ ^  {     
$ _# I2 B% J2 _5 f  ^+ J5 ^. F5 K; m  alert("请输入注册名");     
6 `$ D9 @+ s8 i3 _& j" W  document.sform1.id.focus();     
* X) }3 X" c2 m$ N% R. ?5 z4 T  return false;     % ~, b* E1 x& a: a
  }     
: |: |+ n$ n& w. b: h3 h     
' w) n' e2 Z- |% { for (nIndex=0; nIndex<id.length; nIndex++)     
/ W/ v* k1 n4 W( X  {     
' B! Y, n* m! z& l7 [* q; V; L  cCheck = id.charAt(nIndex);     
1 j3 m, V2 Y" v; t* I  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     3 Q! H7 }* P# j" h
   {     
/ X8 D9 I5 X2 A6 F   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     # W6 R( |. j( n
   document.sform1.id.focus();     
5 _+ _4 G; @0 y7 S   return false;     2 }' P; s/ F3 M
   }     
" G3 X! y& v! Q% H" m. |  a  }
' z1 T: _. z9 U! \7 W& f  chineseid = document.sform1.chineseid.value;     
# i0 D2 ?# w% H) W if (chineseid == "")     
; F/ c" f" b* ]4 P1 q! O. `! ^/ @* s  {     4 |8 I! S1 b  {. J
  alert("请输入中文昵称");     5 L/ U/ j+ y5 ?3 d5 x' E2 J/ T
  document.sform1.chineseid.focus();     
# [) m: y! I0 f0 h* I* b, Q  return false;     
4 ?9 N! V; V& |0 q; s  }    # Q! ~6 z- {4 Q' ~* u2 ^) m
password = document.sform1.password.value;     % l+ D6 n/ m0 E8 ]
if (password == "")     
; E8 g4 a- ^: Z9 G$ x  {     
& c. t" L. {8 Q  alert("请输入登陆密码");     
- P. S# c$ T6 r" D  document.sform1.password.focus();     
; h: L& B. A: Z/ A8 N! l  return false;     ! I7 y6 r) U) g* _# f
  } ( e3 [# p. o2 ]* W
password1 = document.sform1.password1.value;     - P8 ~7 A7 G0 o, N
if (password>password1)     
, o3 ^- m0 p! m: M  {, g: R4 F! d6 N3 b' f. x6 I
     alert("重复密码与登陆密码不相同");     ( l8 C; \+ }/ A( O
  document.sform1.password.focus(); 7 K- Q, ~! C8 \8 i) J1 m3 J1 O
                                document.sform1.password1.focus();     
! H5 I4 {" m9 P+ T3 r) I1 n! B. u  return false;
6 X) s- q( S0 l. X  }  
/ T" O: a/ h5 d: Tif (password<password1)     
) W3 M, {2 @6 b: w# o, L, n2 E  {
" Q4 ~# d* C! z7 k9 g+ h     alert("重复密码与登陆密码不相同");     
% Q7 H0 S/ ^6 T7 O+ g6 O  document.sform1.password.focus(); * _1 L! w8 \7 S! K6 g( g  i5 \
                                document.sform1.password1.focus();     
, i. ]1 t0 q3 K; h. u9 u9 g  return false;7 L1 y- E2 J, m% R* ^0 c3 ?
  } / e# W* z" u1 n
if (document.sform1.email.value == "")     
6 P+ D+ [& h+ q9 ?  {     
# q6 K" v+ m7 o/ q7 ^  alert("请输入您的E-MAIL地址");     7 u* N% {8 c$ |# X* C, E8 {: G
  document.sform1.email.focus();     
( Z% J$ K  W) H  return false;     6 ]/ o  g& }+ r
  }     ! {4 Y$ M9 F- L3 S( q: v$ `
      
  \- T$ o( e' n6 N( Q  D' p* j email=document.sform1.email.value;      
6 U  J5 j) l& [0 t. D7 j4 V) f emailerr=0     : H+ t- V/ I9 U7 b& j
for (i=0; i<email.length; i++)     4 D' Z* X  r2 |& D3 |0 ?$ z- h% }
  {     
0 H' `3 T" I  ~* `  if ((email.charAt(i) == "@") & (email.length > 5))     " H) ]9 f( b: k% v% ~, z
   {     
" O  |. @! z# u8 \5 F# @5 M     emailerr=emailerr+1     
& w) m) j9 l; }' l4 [( M* P/ O   }     
) R3 Z0 F. F* H2 \' s' w  }     
& d+ S# t7 k4 p1 | if (emailerr != 1)     8 o4 Q  ]) W; P; ?" t4 f! C- n( K, R
  {       [' O7 Y( b) |% P% f
  alert("请输入正确的E-MAIL地址");     
9 H& W$ W) [' o; \3 H* d  document.sform1.email.focus();     
  b, q9 f5 K  s' x# U  return false;     : i. l, `; h" {: c+ d* S, V: |% X
  }           
0 C* ^9 Y$ e3 E. h% E8 z- d: X& K2 i  
% x( q! o; x  v3 }: s5 u if (document.sform1.checkask.value=="")
6 K$ `, L% K1 B  {
# [" }% W, D9 X- u+ G8 X, w9 X; u2 @   alert("密码提示问题不能为空");     / q1 b+ u$ g% m- Q' Y# z# _) o
   document.sform1.checkask.focus();     ) q0 Q7 I) U" y/ ^# h$ S- t( G
   return false;  7 J5 o0 O( ~& S5 O' s* Y7 V
  } # ?2 F! N# U1 W% r0 ~' N- \
if (document.sform1.checkans.value=="")
/ J+ w* i1 g5 Z4 q1 `/ m# e  {
4 T# D  C; X6 d' k) [$ }( U   alert("您的密码提示问题答案不能为空"); 0 ?, R7 T0 v$ x
   document.sform1.checkans.focus();     
2 U/ h3 Y: x! v( W* Q$ V   return false;  ; G- k# i" U" _' l
  }5 x4 Z7 V2 f' l, g1 \5 ]% p
return true;     
4 l' c5 v8 N: |+ c     
. G( Y0 c+ Q8 ]} : J1 c" o6 _. M" `5 M4 z" z
</script>

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