标题:
一个注册表单验证的js
[打印本页]
作者:
admin
时间:
2008-1-19 23:39
标题:
一个注册表单验证的js
这个脚本对你可能有帮助:
% l7 z1 v. q6 ?' O" {% D* k
<script language="javascript">
6 I8 ?0 [4 t1 x; p
function IsDigit(cCheck)
9 `) i6 Q9 C3 l3 t2 a
{
( ]( Q7 ]" L& |
return (('0'<=cCheck) && (cCheck<='9'));
! I6 }0 X. @( f, ~! |8 o
}
/ T4 L0 r# C& s. T j5 b: s8 F
' z6 l5 m9 U% p& g: |+ H
function IsAlpha(cCheck)
3 @% ^, n. u0 d: T
{
; I1 q5 o' a( e* j( ?' [# M. n) K
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))
8 T) l& S" ~! [9 A& M
}
' n$ [* `, v! ]! |7 ]1 H! {7 K
' e2 E9 `4 q1 m7 d+ |
function IsaNull(cCheck)
, r8 F! G1 K; }3 M) Y" r
{
2 N/ M2 B! m$ J
return(cCheck != " ")
; w5 \' b0 t+ Q# w1 R/ Y0 E& i
}
+ ]6 u& Y( D" k0 K6 ?) d
+ a! b) X! n8 x V/ X& z, N
function checkform()
' D' W) F. k6 z5 W/ i+ z; ?" g6 q
{
/ O& q7 f6 j) S q" H, s% C
id = document.sform1.id.value;
: k' d/ @3 E" U3 m6 a0 Y
if (id == "")
3 w( c/ g) ^; \& w
{
$ v) q. ~, R: K8 n
alert("请输入注册名");
+ c: d1 c: [# D+ j/ ^* W
document.sform1.id.focus();
6 ]- T' k0 K* }+ ~
return false;
% F7 o* Z9 l5 e* S7 h
}
! F0 q7 l+ H' [
4 f# g& h0 e& n
for (nIndex=0; nIndex<id.length; nIndex++)
# ]# \0 d4 U7 h
{
- D1 H9 o6 i3 Q3 k( i h! p% F4 R
cCheck = id.charAt(nIndex);
9 j# b1 ~! Y7 ~% V, x
if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))
: f! ?- M ]# J' [& ~. T2 P
{
9 _' P9 |' j+ U# o8 Q4 w" |! f$ C
alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");
2 b! E' |7 Q- O9 C6 e
document.sform1.id.focus();
) z+ E, a4 s; [# D% d" h$ ^
return false;
( |# l9 h% |. ?! B2 t
}
0 G/ G, S+ z# |9 [/ S% O6 h; P; I
}
6 F& @4 S- p+ y% A5 i) a
chineseid = document.sform1.chineseid.value;
" {' x* P' b! M. n" D, `, |8 h
if (chineseid == "")
9 a: @5 Q; q3 J5 l+ Q5 _
{
: S. Z) R. ~" i y; N' o7 I' l
alert("请输入中文昵称");
2 K4 u3 @$ }* s6 _+ @( S4 a: e
document.sform1.chineseid.focus();
! {# H) e8 c/ A( `4 @( S5 k( s
return false;
) v: s/ s2 m! U/ [
}
/ F% j. c( O% ]4 s4 z
password = document.sform1.password.value;
1 }, w4 E0 X# m+ @
if (password == "")
6 Q6 j9 e# m8 ?$ {/ |
{
6 J9 _( ~. B3 a
alert("请输入登陆密码");
4 B5 t: I8 r% n3 _( l! y" _1 S8 p
document.sform1.password.focus();
. F( m2 @/ K* K( h u: q
return false;
! e6 b. e- ^; }) q7 I _# Y$ q
}
3 G6 q" o( Z3 x! y& S& {
password1 = document.sform1.password1.value;
" }) |) n( V! w% R( I
if (password>password1)
. M+ x1 }. J; j
{
0 J! V6 c/ M# q8 E9 n
alert("重复密码与登陆密码不相同");
. v8 ?% q% [- n
document.sform1.password.focus();
4 n* J& P$ x5 R" U8 B7 h9 ]! M
document.sform1.password1.focus();
* ]$ w [' `: Y' {5 _, ]+ i
return false;
% h L( p i K8 L6 s3 } r5 i
}
+ g7 A, C) ?- M
if (password<password1)
- S/ s9 h; y- r! A; h6 R/ x
{
. C5 l2 \1 w3 i/ T+ o/ k
alert("重复密码与登陆密码不相同");
) R0 j1 T% \( P& {1 E3 Q
document.sform1.password.focus();
2 _2 y1 g7 U4 x
document.sform1.password1.focus();
1 q1 C/ `4 h! g
return false;
1 C7 e) x/ g* O, K4 d* M% w
}
3 O" X& S7 A6 t$ Y r7 J( V
if (document.sform1.email.value == "")
, m# ^6 ~2 M% z* _- y
{
+ T$ [ A& z1 E" D# R4 O
alert("请输入您的E-MAIL地址");
7 }6 B9 G6 Q# V$ J% _/ ]" g3 q
document.sform1.email.focus();
3 G$ A9 o0 ?, {- l
return false;
Z2 n. G5 a) d8 }( @3 i# y7 G
}
3 _) O4 A$ ]* R- v4 U" U# r9 M# y
+ n I7 A9 P9 R \& q% d3 V: U+ W
email=document.sform1.email.value;
" A7 b N- p4 Q) `. p# N0 P( J) q) s
emailerr=0
2 P L% N% X; C$ P
for (i=0; i<email.length; i++)
W# M8 x* u5 _
{
( M2 L2 H: F) N
if ((email.charAt(i) == "@") & (email.length > 5))
4 _5 w5 o; @2 v; r
{
) n5 i6 ~. d2 O
emailerr=emailerr+1
- P+ _- U; K+ C
}
% w$ ?3 M# Q2 J9 X1 }
}
9 [: Q2 N: G9 @, {5 s' p
if (emailerr != 1)
4 n, p7 \) z3 S# x! }7 x
{
0 Q+ C+ L: p$ Y( _6 L3 N3 M+ K2 t0 N( ?
alert("请输入正确的E-MAIL地址");
- x: T; }5 w1 c
document.sform1.email.focus();
$ i7 [' H. G1 |* \# U8 M
return false;
9 Y6 U. a, |4 p
}
" V& S" v2 p' ^+ \* p6 a! a9 C: A
& h2 U5 N, G. Q1 c5 Q9 y" p
if (document.sform1.checkask.value=="")
8 {1 S7 ?' J. R/ r$ ?
{
/ N! n, U2 o2 `6 Z7 {
alert("密码提示问题不能为空");
; i- n$ q, }) _3 Y
document.sform1.checkask.focus();
3 |/ c, Q4 _) l8 ? F
return false;
O6 e" j/ T0 K2 S" S
}
6 j) L/ k7 U" D. `1 r' A/ A4 I7 P
if (document.sform1.checkans.value=="")
' ~( d9 H X4 U) n5 F [( ~4 `0 J. K" t
{
* [& w7 G) Q" [5 }: \4 C
alert("您的密码提示问题答案不能为空");
+ M. c( P% w$ X4 o8 `
document.sform1.checkans.focus();
# I! x8 a. z2 z, K7 q0 V
return false;
+ _% \) s" @. p/ M' W
}
! j/ _ b0 g6 r
return true;
( b% Q7 g! }9 O; g
+ ]! l6 U- W( J8 ]% e
}
2 o, L* y0 l9 B# P' t4 B4 h
</script>
欢迎光临 捌玖网络工作室 (http://www.89w.org/)
Powered by Discuz! 7.2