Search code examples
javascriptjqueryrulerequired

Validation rule, alert when a field is NOT empty


I know how to check if a field is empty and generate an alert if so:

$('#checkout-form').validate({
    rules: {
        first_name: {
            minlength: 2,
            required: true
        },
        ...
    }
});

But what is the opposite of required? I want to check and generate an alert when my field isn't empty.


Solution

  • $('#checkout-form').validate({
      rules: {
        first_name: {
          minlength: 2,
          required: true,
          equalToParam: ""
        },
    

    But 'Why in the name of all that is holy would you want to do that?'