1、判断是否为年月日时间格式
<script>
//去除字符串首尾空格
String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
//验证是否为日期
function validator(){
if(isDate(document.all.demo1.value.trim())==false){
document.all.demo1.select();
return false;
}
}
function validator(){
if(isDate(document.all.demo1.value.trim())==false){
document.all.demo1.select();
return false;
}
}
/**
判断输入框中输入的日期格式是否为 yyyy-mm-dd 或yyyy-m-d
*/
判断输入框中输入的日期格式是否为 yyyy-mm-dd 或yyyy-m-d
*/
function isDate(dateString){
if(dateString.trim()=="")return true;
//年月日正则表达式
var r=dateString.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r=
if(dateString.trim()=="")return true;
//年月日正则表达式
var r=dateString.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r=