Last Updated: February 25, 2016
·
3.764K
· leonbarrett

jQuery validate for placeholder text

Sometimes you require an input to be required, but if you use placeholder text, or pre-fill with default you still need to validate against the placeholder.

This custom method will do just that. Add this before the call to validate the form.

$.validator.addMethod("placeholder", function (value, element) {
       if (value == $(element).attr('placeholder')) {
          return false;
       } else {
           return true;
         }
    });