在asp自定义验证器中的javascript函数中的日期检查问题

时间:2013-10-09 17:08:29

标签: javascript client-side-validation customvalidator

我为日期检查做了一个简单的功能,一切看起来都很好,但即使我写了正确的日期 - 它也让我觉得它错了

unction checkdateClient(source, arguments)

{
    var validformat=/^(\d{2}).(\d{2}).(\d{4})$/

/ //Basic check for format validity which shold be 01.02.2012 


    var returnval=false
    if (!validformat.test(arguments.value))
        arguments.IsValid = false;

    else
    { //Detailed check for valid date ranges
        var monthfield = arguments.value.split(".")[0]
        var dayfield = arguments.value.split(".")[1]
        var yearfield = arguments.value.split(".")[2]
        var dayobj = new Date(yearfield, monthfield-1, dayfield)
        if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
            arguments.IsValid = false;
        else
            arguments.IsValid = true;
    }

}

0 个答案:

没有答案