I am using jQuery Validator for validations. However for number or digits only the validation not working.
It is accepting special characters also. Instead of letters and special characters I want only digits.
$.validator.addMethod("Length", function(value, element) {
  // var password_regex = this.optional(element) || /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,}$/.test(value);
  if ($(element).val() != '' && $(element).val().length !== 20) {
    return false;
  }
  return true;
}, "Please enter exact 20 digit.");
$("#add_form_id").validate({
  rules: {
    rational_id: {
      // number: true,
      Length: true,
      maxlength: 30,
      digits: true,
    },
  }
);
 
    