标题:
一个注册表单验证的js
[打印本页]
作者:
admin
时间:
2008-1-19 23:39
标题:
一个注册表单验证的js
这个脚本对你可能有帮助:
( m* s) ^* l. Z7 C. U! @9 k
<script language="javascript">
K5 x/ C* L2 ?9 ^4 V; S% q
function IsDigit(cCheck)
9 [, N. V# C4 r# Q+ l1 t @
{
; m% b8 R- V, {) f }( K
return (('0'<=cCheck) && (cCheck<='9'));
- l* b/ m9 r- b# C# \) m" \* t0 b, t4 P
}
& m) b/ ~* P- b
2 C9 l) \: W' s0 O
function IsAlpha(cCheck)
! @6 @5 D! O" H, {# V4 j: K
{
5 v1 S7 t) \3 K% ~2 V
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))
5 M9 P1 b; f% {% \/ Y
}
/ |% R$ J. |0 x' O- L& h% m
5 n9 s1 ?( b: E8 t) h
function IsaNull(cCheck)
I8 G* ?! u% B4 z6 H# }
{
( l8 `( a* K- Y; v! x) D6 j" z! o
return(cCheck != " ")
" i; s: _% f# J0 R3 s0 E4 u* u
}
4 V6 B6 x/ j4 L' Y3 W
1 d1 g8 K$ A# B& J
function checkform()
* {# x& u. o4 g
{
# |$ i* i8 l- U3 Y
id = document.sform1.id.value;
/ S/ @9 h) s% U( \0 |. V% S7 F
if (id == "")
( H1 ]; N' d1 b/ G% W
{
6 o+ F% m: p( f' W+ [! y# L
alert("请输入注册名");
/ y U: G' X! l( ~8 a4 h& _
document.sform1.id.focus();
# K! T7 H! ]3 A: l4 X
return false;
: \0 d9 v& H8 y/ y$ B) @
}
. ?0 s6 o$ W \$ x2 Y* }' s$ f
6 |1 ]: _1 G& ~1 u. M
for (nIndex=0; nIndex<id.length; nIndex++)
4 p- Y5 h: ?5 v
{
3 ~ M- A3 s+ ]# S D# U1 G7 _
cCheck = id.charAt(nIndex);
6 Z% x5 h: U$ K. j8 f5 I
if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))
. X$ v& ?% Y3 V! O& |- i8 ]) f! J
{
: w, _1 z- q @4 `% d; j2 B) u
alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");
$ l5 Y* `3 G5 Y! ]' @
document.sform1.id.focus();
* ]# X3 T) [" c0 O6 V
return false;
3 Z) ]4 A( q$ R5 j: G0 Z8 i
}
( p' {9 k9 w3 }' _( o
}
- t5 k: V6 X1 Q; s
chineseid = document.sform1.chineseid.value;
( K9 D9 |% X2 I9 y9 ?% \( f9 ^/ ^
if (chineseid == "")
0 Y8 @/ ]) l4 E% B9 F4 }) O
{
2 q9 \& G6 z O
alert("请输入中文昵称");
! L' V9 s/ w. U& Y* d4 I
document.sform1.chineseid.focus();
; y" x' V1 E8 c1 ~* d0 o
return false;
# J& C. B6 ^) m1 v* R9 ?
}
% O& z7 p8 C1 J2 Y& d* ]3 f
password = document.sform1.password.value;
5 P, V3 ?7 h, |4 D4 `! t m" T* B( _0 q
if (password == "")
8 \- w5 K# G4 G2 p7 d2 y1 h- r
{
$ t* c. t8 C+ E4 D c
alert("请输入登陆密码");
W6 I( l, U; a% b$ m m. [, _
document.sform1.password.focus();
1 r5 c$ D0 y8 [. x
return false;
2 j0 V$ c8 g& F5 m* ?- A# Z% D! o
}
; o% q, a% Z2 b' W
password1 = document.sform1.password1.value;
' ~& O. @2 q( J4 |
if (password>password1)
/ ?, I# v& Q5 y( v% @
{
* V4 S& b8 H# o5 q" y! K" |
alert("重复密码与登陆密码不相同");
! Y6 A# ^3 H3 K2 n1 [1 X; M( _
document.sform1.password.focus();
2 _; d& t* H1 w. i. p. s
document.sform1.password1.focus();
8 v. m( P5 s- j% I
return false;
. P: ]5 u! m7 q4 j2 Z
}
% k* L8 ]) U/ O7 Z8 D! k
if (password<password1)
6 N1 T0 O0 b8 M* A
{
# M% ^- Z ]+ I" D- d
alert("重复密码与登陆密码不相同");
' c1 s2 r6 {' R/ I8 @; a$ Q; z
document.sform1.password.focus();
& n+ |% c" C0 f
document.sform1.password1.focus();
" B6 }& p# M9 O2 l; b4 a: l: u" t
return false;
4 L3 m/ \" E9 ^5 D
}
0 F8 E7 D/ g: f) L' |) Y
if (document.sform1.email.value == "")
T- j' F: F5 _/ m. V. j% L
{
0 v4 | _! N' H1 \1 r p7 {2 U; D
alert("请输入您的E-MAIL地址");
- w( a( b( R+ T
document.sform1.email.focus();
* r; j, W9 y9 z! N
return false;
% |9 O0 j) k2 V/ F
}
/ V" N. |, i. T3 _! L
6 ]5 X. U4 J9 e+ h
email=document.sform1.email.value;
( w( I5 n/ f: Q2 ~7 d& Z5 L! z% p) D
emailerr=0
' a9 G5 {# l% J) @: |0 }; ?2 x
for (i=0; i<email.length; i++)
@- `) ?* C& |$ d3 b: t) W' t
{
) w% H2 [! c7 K# r# `
if ((email.charAt(i) == "@") & (email.length > 5))
6 }$ D$ J4 @. m8 F* C
{
! |+ r) q% G& n k) ^5 A+ c6 z k1 n, L+ Y
emailerr=emailerr+1
8 `9 W4 y. r: Q4 ]1 x
}
4 E' X7 X. f+ E) a/ E
}
4 n6 P2 a S. F& X+ {5 ]" k
if (emailerr != 1)
% X1 E' `0 D5 l0 E/ ~" Y6 M
{
j/ F. m$ N9 ]. @3 r- [5 k
alert("请输入正确的E-MAIL地址");
/ G4 c3 r) u+ j# L
document.sform1.email.focus();
* e* Q4 o6 w, ?
return false;
9 N% l* @6 h% u X' F4 a
}
/ s+ h+ X: \8 a1 }; E' s& O3 h* p
" X* V. R( q+ D4 p
if (document.sform1.checkask.value=="")
, @0 V0 J6 C9 U- ^
{
7 N* c0 T" S( _
alert("密码提示问题不能为空");
2 u; W; g9 H- W/ y* H7 V
document.sform1.checkask.focus();
1 E, A3 {: ]! D8 V, J1 U" H
return false;
( z1 I' U+ I# j6 u- j8 F9 \
}
" R8 O5 z2 G7 }7 o! e
if (document.sform1.checkans.value=="")
' U/ e' i- f3 o& s6 ?
{
$ C) t0 L; S' n+ }: w. T9 d: w
alert("您的密码提示问题答案不能为空");
: [$ l7 }3 ~5 \3 x- Y
document.sform1.checkans.focus();
# V. v4 i c# M- }
return false;
. q2 f" v( H! z. s: i1 @( `
}
; x% R% @, b, d' A
return true;
+ q$ x2 H9 o2 I0 y/ P
2 I! a$ I, u- I! \% Z+ a% ]1 d
}
% ]$ o. v k$ `3 E2 U
</script>
欢迎光临 捌玖网络工作室 (http://www.89w.org/)
Powered by Discuz! 7.2