标题:
一个注册表单验证的js
[打印本页]
作者:
admin
时间:
2008-1-19 23:39
标题:
一个注册表单验证的js
这个脚本对你可能有帮助:
- E( P) u4 d% s9 G9 {
<script language="javascript">
! h) Y7 ~8 }3 q, L) f! T9 n8 ]
function IsDigit(cCheck)
: K' D: Q/ j, j7 Q
{
% D" z5 U. j# w f B
return (('0'<=cCheck) && (cCheck<='9'));
+ C7 P/ e5 {+ g3 j% P+ l
}
% q9 U. k. l3 E
) E v4 Z+ K; v6 T
function IsAlpha(cCheck)
9 @: t- Q- S2 `- k/ b; U/ H( ?
{
% j' g$ k4 C/ A+ ~
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))
7 h* f" A% H* [; J$ Y6 r
}
' K9 q/ z% l3 n2 E3 C) F. [
1 {9 V6 Z# E4 M
function IsaNull(cCheck)
3 d. U4 S" q, P6 s! W
{
" I2 e* {! ]0 k; n/ x! q) P$ \, S
return(cCheck != " ")
3 w1 G4 G: J1 V5 e( ~; h
}
6 P+ D0 v+ w% S# ~7 L$ L& m; h
4 O! J2 y' E( q* ^. M# ]
function checkform()
, z9 X5 \4 p+ j' b, I
{
# Q- F+ w, x) `0 \
id = document.sform1.id.value;
2 {1 P' E! `( y- v5 `1 T
if (id == "")
2 n2 u5 E [( J _1 f0 B
{
; k9 u7 m9 p* ?# c; M
alert("请输入注册名");
3 |) e. @3 F+ J
document.sform1.id.focus();
! z Q* s0 e8 h, K
return false;
! W1 S: ^7 u( O- B
}
) f" I7 t$ K/ b6 W$ b
7 h# |; S0 d3 l8 p
for (nIndex=0; nIndex<id.length; nIndex++)
1 p& }2 o, {; T5 p0 A/ I
{
9 j1 M: E. f: c+ r* b
cCheck = id.charAt(nIndex);
4 q' i. `& |! r) H; x2 O) p
if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))
: p7 e: r; E/ S% W$ } X1 H
{
$ ^: s) I' ~1 |# o+ Z- ?
alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");
7 }9 {& G3 K9 j ~
document.sform1.id.focus();
" o, x4 G$ W7 C! c7 w. h% I
return false;
; W8 J e1 K7 I
}
1 o$ N9 K1 B \ r5 g$ S) I
}
2 h* m: |" `# d) `; b6 e$ A
chineseid = document.sform1.chineseid.value;
+ `- w1 g, I- w# u2 ?0 k
if (chineseid == "")
$ x. [3 F( R6 I3 j l
{
" N* W; R! J6 k7 B& U
alert("请输入中文昵称");
: d0 g/ n( \' O+ W5 T
document.sform1.chineseid.focus();
$ j) j3 {: k/ T! A% k
return false;
8 G/ Y) z& i b
}
9 Z0 N4 ~% f; E$ n* \/ u
password = document.sform1.password.value;
$ f" J% _) ?7 Y! b# x
if (password == "")
( {5 ?$ K9 G: A' V
{
* L9 U6 s& [8 `/ z9 Y0 W
alert("请输入登陆密码");
0 f* V! j& D( c+ X4 K" o
document.sform1.password.focus();
+ v$ e6 d* r- N7 d" t( c" b
return false;
( D: h5 d7 B) b, q
}
* y& e" G3 p6 }: m7 K9 P& O
password1 = document.sform1.password1.value;
?( A8 o/ }0 o
if (password>password1)
( Y1 l$ _! Y+ {
{
" m: `) p. ~, X4 A, q
alert("重复密码与登陆密码不相同");
# x. x% a# N4 @& Z& l, W/ U
document.sform1.password.focus();
! \" Q$ z# q' v1 |
document.sform1.password1.focus();
5 D4 s8 f4 p# O! i1 `5 p/ e
return false;
" ^5 f6 `' g% t5 E4 N* G
}
- [2 d/ ~: C. Z8 o, I. W
if (password<password1)
8 Q( x) h; _- h
{
7 L M4 U7 {5 @$ W1 U* i
alert("重复密码与登陆密码不相同");
* V2 D+ _3 O8 B
document.sform1.password.focus();
0 N) H8 m5 \8 _0 q
document.sform1.password1.focus();
- r1 d) k7 Q$ E p1 m; U8 Y; l7 p
return false;
# ~3 @: q1 j4 k d
}
/ @' W; {! k# |) o- _3 a k
if (document.sform1.email.value == "")
- d! x& P' _& E* [+ D# l# X
{
0 E. u$ E- u4 @6 [3 }4 ?. D \$ F& N7 v
alert("请输入您的E-MAIL地址");
' l# D0 k1 `' q5 T% W
document.sform1.email.focus();
- ]( x/ P; a' j) ^9 k* a8 i
return false;
R8 Q- T/ d* x+ l- q4 c
}
- S. |2 x" }7 Y% a) y, E; d9 A& X
- P8 Y4 p" W+ w8 }% f1 o# b3 R
email=document.sform1.email.value;
% N- ^# p( K& R
emailerr=0
/ D3 ?7 d/ G* a8 X0 m+ w8 ]7 f
for (i=0; i<email.length; i++)
3 {0 p& k H# a5 ~" [6 u) }
{
" ^2 U! e, n9 H/ x* e I
if ((email.charAt(i) == "@") & (email.length > 5))
2 {0 @% O) y3 ~5 y4 l7 y
{
$ n% G( w* D% s8 Z
emailerr=emailerr+1
; s U# r/ S( S& ^/ s
}
4 p3 T. ?% {+ u
}
4 @" g) X" X+ y5 a) \4 G4 @, O
if (emailerr != 1)
. Y, U) E% R, R) V
{
- R& \5 l3 ~; Y* ]+ ~, M3 e
alert("请输入正确的E-MAIL地址");
( x: I& O9 y* X/ H& q
document.sform1.email.focus();
. ^) h+ }! W" G# |+ g$ M6 U$ `
return false;
9 ~ C. l# N7 g# B2 Y- r
}
! Q# Z7 a) z1 G7 ?# W
" @' v# n$ U A. V1 L
if (document.sform1.checkask.value=="")
" w- n" ]1 v/ g( o% Y
{
) G. k, y, n1 J$ h1 L/ ?' m3 b) t
alert("密码提示问题不能为空");
. M& A' |* _4 m' d, n$ V
document.sform1.checkask.focus();
6 Y$ m, ]" w; k) D0 `% P
return false;
8 S/ k, ?# L T! w) t
}
: ] u1 u9 T! h
if (document.sform1.checkans.value=="")
4 f! C8 f" R. e
{
, Z; d: n9 a/ H6 W+ Q
alert("您的密码提示问题答案不能为空");
( d. c3 n+ Y4 F, m0 c, }# X
document.sform1.checkans.focus();
- N5 X/ q8 q( ~! w
return false;
X1 F; e/ X. C+ K, H5 h/ F. P; G
}
8 J) C( G, g& W' ~1 U: X' [3 C
return true;
/ n3 ~: i2 E( A4 _. X
8 {4 m T+ B) d3 u, A
}
+ g& Y* ^1 D2 |. T
</script>
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2