zoukankan
html css js c++ java
如何用javascript判断录入的日期是否合法
如何用javascript判断录入的日期是否合法
function
IsValidYear(psYear)
{
var
sYear
=
new
String(psYear);
if
(psYear
==
null
)
{
return
false
;
}
if
(isNaN(psYear)
==
true
)
{
return
false
;
}
if
(sYear
==
""
)
{
return
true
;
}
if
(sYear.match(
/
[
^
0
-
9
]
/
g)
!=
null
)
{
return
false
;
}
var
nYear
=
parseInt(sYear,
10
);
if
((nYear
<
0
)
||
(
9999
<
nYear))
{
return
false
;
}
return
true
;
}
function
IsValidMonth(psMonth)
{
var
sMonth
=
new
String(psMonth);
if
(psMonth
==
null
)
{
return
false
;
}
if
(isNaN(psMonth)
==
true
)
{
return
false
;
}
if
(sMonth
==
""
)
{
return
true
;
}
if
(sMonth.match(
/
[
^
0
-
9
]
/
g)
!=
null
)
{
return
false
;
}
var
nMonth
=
parseInt(sMonth,
10
);
if
((nMonth
<
0
)
||
(
12
<
nMonth))
{
return
false
;
}
return
true
;
}
function
IsValidDay(psDay)
{
var
sDay
=
new
String(psDay);
if
(psDay
==
null
)
{
return
false
;
}
if
(isNaN(psDay)
==
true
)
{
return
false
;
}
if
(sDay
==
""
)
{
return
true
;
}
if
(sDay.match(
/
[
^
0
-
9
]
/
g)
!=
null
)
{
return
false
;
}
var
nDay
=
parseInt(psDay,
10
);
if
((nDay
<
0
)
||
(
31
<
nDay))
{
return
false
;
}
return
true
;
}
function
IsValidDate(psYear, psMonth, psDay)
{
if
(psYear
==
null
||
psMonth
==
null
||
psDay
==
null
)
{
return
false
;
}
var
sYear
=
new
String(psYear);
var
sMonth
=
new
String(psMonth);
var
sDay
=
new
String(psDay);
if
(IsValidYear(sYear)
==
false
)
{
return
false
;
}
if
(IsValidMonth(sMonth)
==
false
)
{
return
false
;
}
if
(IsValidDay(sDay)
==
false
)
{
return
false
;
}
var
nYear
=
parseInt(sYear,
10
);
var
nMonth
=
parseInt(sMonth,
10
);
var
nDay
=
parseInt(sDay,
10
);
if
(sYear
==
""
&&
sMonth
==
""
&&
sDay
==
""
)
{
return
true
;
}
if
(sYear
==
""
||
sMonth
==
""
||
sDay
==
""
)
{
return
false
;
}
if
(nMonth
<
1
||
12
<
nMonth)
{
return
false
;
}
if
(nDay
<
1
||
31
<
nDay)
{
return
false
;
}
if
(nMonth
==
2
)
{
if
((nYear
%
400
==
0
)
||
(nYear
%
4
==
0
)
&&
(nYear
%
100
!=
0
))
{
if
((nDay
<
1
)
||
(nDay
>
29
))
{
return
false
;
}
}
else
{
if
((nDay
<
1
)
||
(nDay
>
28
))
{
return
false
;
}
}
}
else
if
((nMonth
==
1
)
||
(nMonth
==
3
)
||
(nMonth
==
5
)
||
(nMonth
==
7
)
||
(nMonth
==
8
)
||
(nMonth
==
10
)
||
(nMonth
==
12
))
{
if
((nDay
<
1
)
||
(
31
<
nDay))
{
return
false
;
}
}
else
{
if
((nDay
<
1
)
||
(
30
<
nDay))
{
return
false
;
}
}
return
true
;
}
查看全文
相关阅读:
DockerFile构建镜像
docker基本命令
docker持久化
JS 中 this 指向问题
解决"/usr/local/bin/dockercompose: Permission denied"问题
docker配置国内镜像
docker网络
国内常用镜像地址
Visual Studio中快捷键收缩和展开代码段方法
STM32中关于RCC时钟的理解
原文地址:https://www.cnblogs.com/dahuzizyd/p/javascript_Date_Check.html
最新文章
使用ASP.NET MVC3 实现一个访问统计系统
谈谈用户体验,也算是给园子的一点建议
Web服务器配置浅谈
支持回车换行的DataGridView
CAD图纸比较 1.0.0(DwgCompare)
SimplePath 简单路径类
在博客园安了个家
故事新编书评
由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作
.net多线程
热门文章
XML序列化成功反序列化失败以及xml 十六进制值 0x0E)是无效的字符
IPSEC造成网络Destination host unreachable
java mysql与.net MSSQL性能测试
Codeforces Round #758 (Div.1 + Div. 2)A B
CodeForces 1271B Blocks
DFS剪枝与搜索
DotnetBar SuperTabIControl实现 MDI效果
关于asp.net 调用ActiveX的问题,求解
10690三网合一电商短信
docker搭建镜像仓库
Copyright © 2011-2022 走看看