Dynamic jQuery Validate error messages with AddMethod based on the element

前端 未结 6 1548
一向
一向 2020-11-27 19:14

Let\'s say I have a custom AddMethod to jQuery Validate like:

$.validator.addMethod(\'min-length\', function (val, element) {
    // do stuff

// the error m         


        
6条回答
  •  时光取名叫无心
    2020-11-27 19:27

    late to the party here, but this seems to work for me:

    jQuery.validator.addMethod("minDate", function(value, element, param) {
        var inputDate = new Date(value);
        return (inputDate >= param)
        }, function(param, element) {
            return 'Enter a date greater than or equal to ' + $.datepicker.formatDate("M d, yy", new Date(param));
    });
    

    where the minDate value has previously been set on the control to validate something like this:

    $('form:first').validate({
        rules: {
            "date-filed": {
                minDate: new Date(2000,0,0)
            },
    ...
    

提交回复
热议问题