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 < 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?

1 Answer 1


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.

  • Onblur wont work, when user directly submit button with out enter any text.
    – Kalidasan
    Dec 20, 2016 at 9:25
  • Expecting custom validation to stop submit action.
    – Kalidasan
    Dec 21, 2016 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.