富贵资源网 Design By www.hznty.com
最简单的
复制代码 代码如下:
function isValidDate(dateStr) {
var matchArray = dateStr.match(/^[0-9]+-[0-1][0-9]-[0-3][0-9]$/)
if (matchArray == null) {
alert("Invalid date: " + dateStr);
return false;
}
return true;
}
function isValidDate(dateStr) {
var matchArray = dateStr.match(/^[0-9]+-[0-1][0-9]-[0-3][0-9]$/)
if (matchArray == null) {
alert("Invalid date: " + dateStr);
return false;
}
return true;
}
第二种
复制代码 代码如下:
<script language=javascript>
String.prototype.isDate = function()
{
var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null)return false; var d = new Date(r[1], r[3]-1, r[4]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}
alert("2002-01-31".isDate());
alert("2002-01-41".isDate());
</script>
<script language=javascript>
String.prototype.isDate = function()
{
var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null)return false; var d = new Date(r[1], r[3]-1, r[4]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}
alert("2002-01-31".isDate());
alert("2002-01-41".isDate());
</script>
第三种,比较复杂的
复制代码 代码如下:
<script language=javascript>
String.prototype.isTime = function()
{
var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
if(r==null)return false; var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}
alert("2002-1-31 12:34:56".isTime());
alert("2001-2-29 12:54:56".isTime());
alert("2002-1-41 12:00:00".isTime());
</script>
复制代码 代码如下:
function isValidDate(dateStr) {
var matchArray = dateStr.match(/^[0-9]+-[0-1][0-9]-[0-3][0-9]$/)
if (matchArray == null) {
alert("Invalid date: " + dateStr);
return false;
}
return true;
}
function isValidDate(dateStr) {
var matchArray = dateStr.match(/^[0-9]+-[0-1][0-9]-[0-3][0-9]$/)
if (matchArray == null) {
alert("Invalid date: " + dateStr);
return false;
}
return true;
}
第二种
复制代码 代码如下:
<script language=javascript>
String.prototype.isDate = function()
{
var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null)return false; var d = new Date(r[1], r[3]-1, r[4]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}
alert("2002-01-31".isDate());
alert("2002-01-41".isDate());
</script>
<script language=javascript>
String.prototype.isDate = function()
{
var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null)return false; var d = new Date(r[1], r[3]-1, r[4]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}
alert("2002-01-31".isDate());
alert("2002-01-41".isDate());
</script>
第三种,比较复杂的
复制代码 代码如下:
<script language=javascript>
String.prototype.isTime = function()
{
var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
if(r==null)return false; var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}
alert("2002-1-31 12:34:56".isTime());
alert("2001-2-29 12:54:56".isTime());
alert("2002-1-41 12:00:00".isTime());
</script>
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...