What must be instead of element.data('maxLength') ?
My target is to check the value without the spaces. That is what I need.
So, standart maxLength is unsuitable for me.
$.validator.addMethod("numberLength", function(value, element) {
return value.replaceAll(' ', '').length <= element.data('maxLength');
}, '-');
...
price: {
numberlength: 12
}
This is the maxlength
method from within the plugin...
maxlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || length <= param;
}
Create your custom method based on the default function...
$.validator.addMethod("numberLength", function( value, element, param ) {
var trimmedvalue = value.replaceAll(' ', '');
var length = $.isArray( trimmedvalue ) ? trimmedvalue.length : this.getLength( trimmedvalue, element );
return this.optional( element ) || length <= param;
}, '-');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.