返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:8 ~; T7 \* V9 C/ B  N
<script language="javascript">     
/ ^8 q! E- t2 h3 L! |% N, {" l8 n% Ofunction IsDigit(cCheck)     , W9 A8 r+ L4 W8 B* W: o
{     / G: ^) C: i3 n& ~5 @! G
return (('0'<=cCheck) && (cCheck<='9'));     
) U3 L; C; y& c3 T }     
4 E1 q- l- }, }5 H+ F     ( I; e" g! r2 ~, {4 y8 G! P9 r+ Y
function IsAlpha(cCheck)     ( z4 a$ w& z. H# L
{     
8 A8 u; y3 f9 t# m+ u& a) N return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     5 e4 G. j' P; p7 e8 _
}              
) \' I% O1 d7 y" W- G      
) e! {/ ^% L3 ^5 T2 f1 Ffunction IsaNull(cCheck)         
8 w' j' y$ D9 x, f; e2 V1 I5 l# I {         
  V! q" O) w  v1 u8 Z7 k) Z$ Q) d return(cCheck != " ")         
( [) m# b0 C) \3 E% p2 c }                               3 u7 Q7 g+ R; K/ ]" m/ I2 I
      ' N( u$ x3 \4 e  Y
function checkform()     
( \% F1 a4 ~9 ^5 p" Z; @4 h- O! K5 J{ 9 {. m# R6 ?" R! m, [  G
  id = document.sform1.id.value;       ?' c- v: z1 p3 c3 T
if (id == "")     , B! P0 A, |. ^/ D% G! Z0 P4 N
  {     
* c  ^5 B+ ?9 \% A; c) Z' `  alert("请输入注册名");     5 x) s2 x& K. n5 w0 ]
  document.sform1.id.focus();     
0 E, q9 J. X/ l- B( b- U, `% P  return false;     
# J5 G3 y: f9 D) d% V  }       ^& r. m4 ]; Q0 ]
     / k/ Z1 b( y5 m9 n% |  o+ r0 n5 V
for (nIndex=0; nIndex<id.length; nIndex++)     
! ^, J( r4 b% _* R  {     1 w' m7 f) S+ S0 R. w$ F
  cCheck = id.charAt(nIndex);     
' Z3 ]% k1 U1 L1 n3 x' z  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
( @5 [  z3 q' B: N% r. j& b, a   {     
4 l# Y& m# O! I& P% w   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
8 g6 P2 v, [6 N. q: s" G   document.sform1.id.focus();     4 U# S/ {" E2 z8 J) e1 I
   return false;     2 L: V+ u+ R% c& n% t- Z( E/ n
   }     
/ }; J/ Y8 W+ M$ Q, Q; ]  } ) H- c% s8 K# y( K5 \
  chineseid = document.sform1.chineseid.value;     
0 S, w  i# D6 T" P2 Y if (chineseid == "")     
( X: l7 J, r9 g2 T  {     
) ~! t5 t. [4 V" H  alert("请输入中文昵称");     " U6 p2 P0 g( V: K: E( L
  document.sform1.chineseid.focus();     / _; N6 r$ l( N7 I- R0 B! T4 t
  return false;     " [- R  m+ @% p4 R" L( t
  }   
" [; M; j, s" v& z) c! L! d password = document.sform1.password.value;     
6 B( A/ y, X0 o. d$ O if (password == "")     
2 @- K5 a( C; c+ m' e" ^  {     " G+ O3 u  K( m( W( x  t
  alert("请输入登陆密码");     % K. [/ d9 t9 O( P8 Q
  document.sform1.password.focus();     
( M0 C# C. n2 p& Z9 o: h( ]: k, z  return false;     
4 s% G  ^5 g/ y$ ~0 p7 V3 o; q6 O  } + Y* \9 U" P' F; T6 Z3 U  b
password1 = document.sform1.password1.value;     
' A3 K( t( c% N; K6 } if (password>password1)     
! x4 R* J" j( S3 f  {
- m# W  X; m/ D0 I$ U" N     alert("重复密码与登陆密码不相同");     ! w- x+ g' v6 p- {  z
  document.sform1.password.focus();
  j: [& r+ Y( D2 d                                document.sform1.password1.focus();     
( O% |4 \+ |& H/ p% ~8 C  return false;/ V. l5 A8 c+ T2 h# C: P  J
  }  
3 Y0 I% ]- J4 k; S4 H2 @( \' mif (password<password1)     4 p; p# L2 O' v; D% y; P% [/ K
  {
; \6 x- M  E( P$ r' S* H) q3 ^     alert("重复密码与登陆密码不相同");     4 [1 s; u! R9 O
  document.sform1.password.focus(); " |6 y1 c/ F3 \: `) y! ]: g/ ?1 M0 E
                                document.sform1.password1.focus();     
# m" ^8 C) I' w  p  return false;! p! ~) L& _3 ~3 i+ M0 l
  } 4 x1 ~6 F8 |$ N  Q; d) j4 c4 g
if (document.sform1.email.value == "")     
$ x) E- X1 u1 f) v3 S6 e  {     # a: @2 u) {/ Z9 g
  alert("请输入您的E-MAIL地址");     ( l' G' M/ C+ i/ D) f6 B
  document.sform1.email.focus();     
8 V, q& v* s+ L" o  z+ Z4 {  return false;     # |8 d5 K+ e9 a- {2 v& t0 E
  }     9 ~* g+ \4 B& Y/ m- b- D
      
6 Z) C# v* _2 u" _$ f email=document.sform1.email.value;      
' ^* j+ ?1 a3 Q/ H7 Y emailerr=0     ; k8 l* D5 y1 a* l$ \- F+ t
for (i=0; i<email.length; i++)     + X2 ~8 t* P2 e- h) Z
  {     
- c' L) j: X3 c+ D" Z; W( B  if ((email.charAt(i) == "@") & (email.length > 5))     
! U$ ]2 _7 O6 c/ [1 p/ R9 `   {     
# Y- `; V* O0 [7 E     emailerr=emailerr+1     
" w  O0 c" E1 }: w# B  d5 y   }     
. U& z1 G- L# Z* P  }     $ L* ^+ m; U+ u6 x- M
if (emailerr != 1)     , }/ w7 L1 v* \; H. N
  {     5 x$ ~% N2 Q$ {! a7 J
  alert("请输入正确的E-MAIL地址");     + i. M1 n& C9 V8 Y9 C; g
  document.sform1.email.focus();     
7 `9 p0 T8 g5 L4 K+ J  return false;     
- m" c0 |& e9 Y* e  }           
2 u  h/ a1 s1 D- u6 w+ q: Y# o0 |  
% d; B- s3 i$ j* D) ?/ l if (document.sform1.checkask.value=="") 2 Y. j! y, F8 n" X! w2 ~: M
  { 0 s% _9 y; N1 N% y
   alert("密码提示问题不能为空");     & i& a# o8 }1 Z1 U7 U3 O
   document.sform1.checkask.focus();     
" F) X# W" Q" q' q3 g" R% q. \) I   return false;  
: b- h& y' Z7 }' m/ b  } * x" J! |- o3 U
if (document.sform1.checkans.value=="") : r! y* X# t% L9 \; [( ?) m
  {
, E+ k% L0 O+ N4 y   alert("您的密码提示问题答案不能为空"); / ~/ {) q) F, ?6 ]7 y
   document.sform1.checkans.focus();     / r4 \! q8 w( l) t7 t* S( ~
   return false;  0 h) E* P1 ~% A5 O
  }, H+ p" a7 O$ V5 G) Q9 ?3 w9 S- Z
return true;     % }+ @* x4 D: S2 ~* {7 z% d
     
; S+ t9 G8 |7 p5 i} 2 J% u' O! |- R, q$ W
</script>

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