Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have yet to find a snippet or a solution to enforce a minimum comment length.

Most validation modules deal with fields.

share|improve this question
up vote 4 down vote accepted

Add a custom validator to form using hook_form_alter in your custom module.

function custom_mod_form_alter(&$form, &$form_state, $form_id){
  switch($form_id){
    case 'comment_form':
      $form['#validate'] = array_merge( $form['#validate'], array('custom_validator'));
    break;
  }
}

Define the logic to restrict the length of comment length

function custom_validator($form, $form_state){
    if(strlen($form_state['values']['comment']) < 50)
       form_set_error('comment', t('No No....'));
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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