jquery.validation - how to ignore default values when validating mandatory fields

前端 未结 8 1039
一向
一向 2020-12-03 00:00

I am using jquery validation plugin to validate a registration form.

Each text input field has instructions pre-filled as values in the input box

ex: for a

相关标签:
8条回答
  • 2020-12-03 00:40

    for me the above only worked with the following changes:

    jQuery.validator.addMethod("defaultInvalid", function(value, element) 
    {
        switch (element.value) 
        {
            case "Your Name":
                if (element.name == "element_name") return false;
                break;
            default: return true; 
                break;
        }
    });
    
    0 讨论(0)
  • 2020-12-03 00:43

    I think this is better:

    jQuery.validator.addMethod("defaultInvalid", function(value, element) 
    {
        return !(element.value == element.defaultValue);
    });
    
    0 讨论(0)
提交回复
热议问题