标题:
一个注册表单验证的js
[打印本页]
作者:
admin
时间:
2008-1-19 23:39
标题:
一个注册表单验证的js
这个脚本对你可能有帮助:
2 U( j( |' x4 q$ i4 t
<script language="javascript">
+ C, H8 g* } g
function IsDigit(cCheck)
' S/ [( e. \# K% b* w
{
) J& Z# ?6 V8 D/ N) H
return (('0'<=cCheck) && (cCheck<='9'));
1 a8 W6 t; K7 \# b6 I5 O& s
}
# h, |- x0 I2 Y& X/ x9 l6 X! Z
! {/ s* t4 V8 d* I8 Y: Q7 [
function IsAlpha(cCheck)
( v0 s7 _5 Z u" t; d4 E
{
; _1 _- c3 ^( ?1 B
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))
( O" o% I' {) D8 r: N3 c
}
: U) [/ l; ~5 W2 C
/ {5 Q2 o4 x: y* ?: |$ p$ M7 N/ K
function IsaNull(cCheck)
; r% _% x/ }5 I- s9 B1 X% S
{
; |8 ] @9 q0 m( ^" ]. @: O0 r
return(cCheck != " ")
/ Y2 e# E7 y/ [+ u
}
! _; T& z5 m: T( a
% ]- k+ f- X, H% ^1 `1 ? X
function checkform()
: m- z9 N# `0 i' h0 E" L' t
{
5 m! Z9 ?$ M- D' Y' k+ J
id = document.sform1.id.value;
0 ?( @! m3 C7 O* S9 G
if (id == "")
1 [; K @7 W, ?2 `7 M3 O3 G6 P" e) u; w
{
7 L+ [; o& i: Q: X4 c
alert("请输入注册名");
" k) r& q+ o+ p$ ?9 e3 E
document.sform1.id.focus();
2 C9 i! c$ c* H# E
return false;
3 b& A/ s. w: L
}
# r" k4 b7 r; C& d. r9 m+ N: o
0 o" Q- p: P+ `
for (nIndex=0; nIndex<id.length; nIndex++)
. x- T( a7 g' q" M+ m8 p1 _9 [3 i! U
{
- B% \; t1 ?/ X$ |+ k, ]9 l0 o
cCheck = id.charAt(nIndex);
; l0 p! G9 ]# T; \8 k
if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))
9 d" l4 |: ^$ x3 i
{
" T+ j. D, R4 `; q7 M6 _! k
alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");
& |$ e. ~" J9 J9 v5 a* v0 c; _
document.sform1.id.focus();
6 y8 K" e! d: p( b1 \* x
return false;
! f$ f9 B% ~3 m" L
}
9 H) h" d) V- g- F7 \4 ^- Q2 z
}
8 \4 C. ]2 Y9 F9 s7 x/ A* Q$ S3 G# m
chineseid = document.sform1.chineseid.value;
9 `' s% O; `# W, ]- ]
if (chineseid == "")
7 P: T7 ~+ ~* `' j6 i
{
5 d3 N: `5 w7 p; m* [' j
alert("请输入中文昵称");
, e& i+ X5 V2 l( Z7 m, \; n
document.sform1.chineseid.focus();
6 G( G- v: V6 \& s, D3 q% Z. a
return false;
2 Z; v* t* E5 ?4 h" B
}
, v- w! s+ i( b$ i; H$ `: k
password = document.sform1.password.value;
! |3 ` ^3 H) @ W
if (password == "")
# l! T) t9 T. F3 w) X& V9 V
{
% b# n" O" r8 G6 n; ~* t
alert("请输入登陆密码");
6 s& [" |' t/ G6 u# x/ _( `4 `
document.sform1.password.focus();
, i5 |4 }7 i' U( `1 }
return false;
: |) D6 R$ y7 o3 t! L# Y
}
; Z3 `5 d, ~) X, q! v5 o4 R1 T
password1 = document.sform1.password1.value;
# w; L% ]( k* H/ T$ d
if (password>password1)
* t! i: _, @; l5 { r# @- K* K
{
' H5 z8 D' @' L: N
alert("重复密码与登陆密码不相同");
8 O$ n/ Z1 P& D. S& g) u1 c
document.sform1.password.focus();
( k& m/ N$ o$ W3 \ l E. a
document.sform1.password1.focus();
* }, o0 t8 Y+ o& O( z! x3 U) Y' F
return false;
2 T$ F2 V" U" g$ W- Q4 q3 }0 o, c
}
% r& D( a$ x' Q, T4 K
if (password<password1)
4 @' K U/ n7 A9 ^/ r3 Y& w2 k- l
{
6 X$ l6 U: O% l7 i& R
alert("重复密码与登陆密码不相同");
4 Y, j9 H+ u$ i5 }
document.sform1.password.focus();
3 c2 S$ r4 @3 b0 J2 ^9 i
document.sform1.password1.focus();
: r9 q+ n1 ~. x( M# e
return false;
9 A) ]+ U) U8 Z: X
}
5 K" s4 `* D0 K d) v$ x
if (document.sform1.email.value == "")
5 `2 J5 h4 {3 J. J# m
{
+ }) P! g2 | N* E. s/ r& {# q
alert("请输入您的E-MAIL地址");
- R( @# V" G- R( e
document.sform1.email.focus();
. @! K) t. E/ M0 v" q: w# v* K8 T
return false;
- M S; U0 t/ M8 o- c: ~9 p$ l2 k
}
' y# x" ~; L+ [3 r) [# v
* ?4 S6 e I f, m
email=document.sform1.email.value;
. H/ J+ \* u/ U; D2 A" {
emailerr=0
" ^# V2 e4 D: e. @2 K# z" ^% ~7 E
for (i=0; i<email.length; i++)
# e! b( A" [. ? H8 s, C" n
{
+ j1 a, l. C( T- F E! {3 f
if ((email.charAt(i) == "@") & (email.length > 5))
5 d3 S a9 d; v/ L9 v$ v! a
{
5 z9 c" P( w: N( F% _7 [- N
emailerr=emailerr+1
4 p4 ]) b: s' o8 a- V
}
8 M) j! n+ e1 b# D
}
! {3 l: I( E( W$ H6 Q5 e* `: ^' x
if (emailerr != 1)
4 G$ L! F6 P0 T) Y: [
{
3 r* b: t" u! V& E" @+ a
alert("请输入正确的E-MAIL地址");
* C* C+ Y3 c# r- d( D5 Z( i' F
document.sform1.email.focus();
' x Q$ g( b) a% v! A
return false;
5 K R9 U1 V( i- K+ z2 k: u, Z
}
) x' q/ g. n$ c& d
2 o$ a7 Q* V2 y0 [# a8 m2 l0 }
if (document.sform1.checkask.value=="")
7 u3 {. d* W/ R8 D
{
0 R2 \' h# X+ U* f2 B8 B
alert("密码提示问题不能为空");
$ V# X, o3 I: @, @+ x6 F
document.sform1.checkask.focus();
1 @% U( m7 l/ W0 C. z& C
return false;
7 |. a( k3 U, t1 V8 Y6 E
}
' Z% A( X+ E- A! R
if (document.sform1.checkans.value=="")
* |# _+ m% k+ M5 i
{
1 N- N. z! M0 K) z9 W
alert("您的密码提示问题答案不能为空");
1 x+ g1 i$ {% A0 c
document.sform1.checkans.focus();
( d, @; @/ `& c2 X: ]; q
return false;
) s& i6 e7 v: E
}
9 v0 _; d$ |, n/ v% e
return true;
7 Z. h: M: o+ H8 Y) S8 p% a
# e! C# V7 I! o" p% \# \6 h# d! f5 i
}
5 f& J1 ^$ t5 x; w
</script>
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2