Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery验证未来日期addMethod();_Jquery_Date_Jquery Validate - Fatal编程技术网

jquery验证未来日期addMethod();

jquery验证未来日期addMethod();,jquery,date,jquery-validate,Jquery,Date,Jquery Validate,jquery验证插件的一些问题,以及将来的日期 我有这样一个输入字段: <input id="date_hinfahrt" class="gui-input error" type="date" required="" name="datefuture" placeholder=" DD/MM/YYYY" aria-required="true" aria-invalid="true"> $("#datefuture").mask('99/99/9999', {placehold

jquery验证插件的一些问题,以及将来的日期

我有这样一个输入字段:

<input id="date_hinfahrt" class="gui-input error" type="date" required="" name="datefuture" placeholder=" DD/MM/YYYY" aria-required="true" aria-invalid="true">
 $("#datefuture").mask('99/99/9999', {placeholder:'_'});
对于验证插件,我尝试了这个addMethod(); 但它不起作用,我希望有人能帮助我

$.validator.addMethod("minDate", function(value, element) {
    var now = new Date(); 
    var myDate = new Date(value);
    var mD = ("0" + (myDate.getDate())).slice(-2) + '/' + ("0" + (myDate.getMonth()+1)).slice(-2) + '/' + myDate.getFullYear();
    var nowdate = ("0" + (now.getDate())).slice(-2) + '/' + ("0" + (now.getMonth()+1)).slice(-2) + '/' + now.getFullYear();
    return this.optional(element) || mD > nowdate;
    // else alert('Das passt nicht!' + mD +  '   ' + nowdate);
});

您可以直接比较日期,不需要进行所有的连接

jQuery.validator.addMethod("minDate", function (value, element) {
    var now = new Date();
    var myDate = new Date(value);
    return this.optional(element) || myDate > now;

    // else alert('Das passt nicht!' + mD +  '   ' + nowdate);

});
你摆弄小提琴的方式也有问题。您有
name=“date\u hinfahrt”
,但在
规则中:
选项中使用了
datefuture
。另外,
formtools.js
不适用于
type=“date”
输入,因此它清空了字段,导致它总是抱怨该字段是必需的;我将其更改为
type=“text”


我不明白所有的切片和连接?为什么现在不
myDate>
?请提供一个plunkr或JSFIDLE示例。这是小提琴