Add custom validation on views exposed filter block form I have one content type called Address. It has title, body, etc.. fields.
Initially Created view for Address.

Later client wants to add search field for this view. 
So created exposed filter block for body field.

Now search block with results working fine.

But challenge is, we need MINLENGTH validation to that search field.

Added $form['#validate'][] = _custom_validate; in form_alter.

if ($my_field_length &lt; 4) {
  form_set_error('my_field', t('Please enter minimum 3 characters.'));
}



First Question: This validation is happening on each page load but it is not triggering when we submit form (This is ajax form).
Second question: Is that any possible to stop validation or auto submit on intial page load?
There are many issues reported for this behavior on Drupal.org and Drupal Answers.

As a work around, you can try HTML5 pattern attribute to add minimum length validation, check example here.

Or add a small JS snippet to validate input field on blur event.