Form validation handler for ban_ip_form().
function ban_ip_form_validate($form, &$form_state) {
$ip = trim($form_state['values']['ip']);
if (db_query("SELECT * FROM {ban_ip} WHERE ip = :ip", array(
':ip' => $ip,
))
->fetchField()) {
form_set_error('ip', t('This IP address is already banned.'));
}
elseif ($ip == ip_address()) {
form_set_error('ip', t('You may not ban your own IP address.'));
}
elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) == FALSE) {
form_set_error('ip', t('Enter a valid IP address.'));
}
}