Two classes of validators:
- Required (empty/non-empty) validation
- Format validation (phone number, zip/postal code, etc)
Don’t show both a required error and a format error at the same time. In other words, format validation errors are NOT shown for empty fields (doesn’t matter if they are required or not).
Pseudocode for an isValid method:
if( valueNotEmpty ) {
return hasFormatValidator ? isFormatValidatorValid() : true;
} else {
return !isRequiredField;
}
Side note: A more complicated version of this has two different modes of operation for presubmit and postsubmit (tried to submit, but fields have errors), but may not produce enough value for the code required.