如何用正则表达式验证时间的正确性?

2026-03-30 08:201阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计203个文字,预计阅读时间需要1分钟。

如何用正则表达式验证时间的正确性?

复制代码+代码如下:javascriptfunction CheckTime() { var checkValue=new RegExp(^([0-2][0-6]:[0-5][0-9]:[0-5][0-9])$); var stControl=document.getElementById(txtStartTime); var stValue=stControl.value; if (stValue.match(checkValue)) { alert(时间格式正确!); } else { alert(时间格式错误!); }}

复制代码 代码如下:
function CheckTime()
{
var checkValue = new RegExp ("^\[0-2]{1}\[0-6]{1}:\[0-5]{1}\[0-9]{1}:\[0-5]{1}\[0-9]{1}") ;
var stControl = document.getElementById("txtStartTime") ;
var stValue = stControl.value ;
if (stValue == "")
{
alert("请填写开始时间") ;
return false ;
}
if (!(checkValue.test(stValue)))
{
alert("请填写公司内部规定时间") ;
return false ;
}
var etControl = document.getElementById("txtEndTime") ;
var etValue = etControl.value ;
if (etValue == "")
{
alert("请填写结束时间") ;
return false ;
}
if (!(checkValue.test(etValue)))
{
alert("请填写公司内部规定时间") ;
return false ;
}
return true ;
}

如何用正则表达式验证时间的正确性?

本文共计203个文字,预计阅读时间需要1分钟。

如何用正则表达式验证时间的正确性?

复制代码+代码如下:javascriptfunction CheckTime() { var checkValue=new RegExp(^([0-2][0-6]:[0-5][0-9]:[0-5][0-9])$); var stControl=document.getElementById(txtStartTime); var stValue=stControl.value; if (stValue.match(checkValue)) { alert(时间格式正确!); } else { alert(时间格式错误!); }}

复制代码 代码如下:
function CheckTime()
{
var checkValue = new RegExp ("^\[0-2]{1}\[0-6]{1}:\[0-5]{1}\[0-9]{1}:\[0-5]{1}\[0-9]{1}") ;
var stControl = document.getElementById("txtStartTime") ;
var stValue = stControl.value ;
if (stValue == "")
{
alert("请填写开始时间") ;
return false ;
}
if (!(checkValue.test(stValue)))
{
alert("请填写公司内部规定时间") ;
return false ;
}
var etControl = document.getElementById("txtEndTime") ;
var etValue = etControl.value ;
if (etValue == "")
{
alert("请填写结束时间") ;
return false ;
}
if (!(checkValue.test(etValue)))
{
alert("请填写公司内部规定时间") ;
return false ;
}
return true ;
}

如何用正则表达式验证时间的正确性?