0

我在使用 dateITA 验证添加方法(Bassistance jQuery Validate - http://bassistance.de/jquery-plugins/jquery-plugin-validation/)和 IE9 时遇到了一些问题。即使使用像 20/10/1974 和 20/10/1985 这样的有效测试,我也得到了无效的日期。

我不明白为什么 Internet Explorer 在这种情况下无法验证这种日期格式,你能帮我理解为什么吗?

JS:

/**
 * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
 *
 * @example jQuery.validator.methods.date("01/01/1900")
 * @result true
 *
 * @example jQuery.validator.methods.date("01/13/1990")
 * @result false
 *
 * @example jQuery.validator.methods.date("01.01.1900")
 * @result false
 *
 * @example <input name="pippo" class="{dateITA:true}" />
 * @desc Declares an optional input element whose value must be a valid date.
 *
 * @name jQuery.validator.methods.dateITA
 * @type Boolean
 * @cat Plugins/Validate/Methods
 */
jQuery.validator.addMethod("dateITA", function(value, element) {
    var check = false;
    var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
    if( re.test(value)) {
        var adata = value.split('/');
        var gg = parseInt(adata[0],10);
        var mm = parseInt(adata[1],10);
        var aaaa = parseInt(adata[2],10);
        var xdata = new Date(aaaa,mm-1,gg);
        var currentdata = new Date();   

        if (xdata.getFullYear() >= currentdata.getFullYear()-3) {
            check = false;
        }   
        else if ( ( xdata.getFullYear() === aaaa ) && ( xdata.getMonth() === mm - 1 ) && ( xdata.getDate() === gg ) ){
            check = true;
        } else {
            check = false;
        }
    } else {
        check = false;
    }
    return this.optional(element) || check;
}, "Please enter a correct date");

HTML:

<label for="pBirth" class="pBirth">
    <span>Birth <em>*</em></span>
    <input type="text" maxlength="10" name="pBirth" required  class="smally01 dateITA" />
</label>
4

0 回答 0