Validate a comment from a custom module
Assuming you're working in Drupal 6:

/**
 * Implementation of hook_comment().
 */
function mymodule_comment(&amp;$a1, $op) {
  switch ($op) {
    case 'validate':
      $subject = $a1['subject'];
      $comment = $a1['comment'];
      // validate here
      break;
  }
}


In Drupal 7 hook_comment() is gone, being replaced by a set of hooks hook_comment_view(), hook_comment_load(), etc. Unfortunately there is no hook_comment_validate() but see this answer for a solution.