javascript验证日期是否yyyyMMdd格式

function Submit1_onclick() {
    
if( Text2.value == "" || Text1.value == ""){window.alert('日期必须输入!');}
    
else{if(/^\d{4}-\d{2}-\d{2}$/.test(Text1.value)&&/^\d{4}-\d{2}-\d{2}$/.test(Text2.value))
    {window.open('http:
//localhost/Abiz/Report.aspx?RentStart='+Text1.value+"&RentEnd="+Text2.value);}else{window.alert('日期格式不正确!');}}
}
原文地址:https://www.cnblogs.com/sskset/p/197928.html