domain_valid_domain

Versions
domain
domain_valid_domain($subdomain)

Validate the domain against all correctable errors.

Note that we decided not to check for valid TLDs here.

Parameters

$subdomain Domain string to check.

Return value

string Empty if valid, error message on invalid.

Code

./domain.module, line 827

<?php
function domain_valid_domain($subdomain) {
  $error_list = array();
  // Check for one colon only.
  if (substr_count($subdomain, ':') > 1) {
    $error_list[] = t('Only one colon (:) is allowed.');
  }
  // If a colon, make sure it is only followed by numbers.
  else if (substr_count($subdomain, ':') == 1) {
    $parts = explode(':', $subdomain);
    $port = (int) $parts[1];
    if (empty($port) || $port != (float) $parts[1]) {
      $error_list[] = t('The port protocol must be an integer.');
    }
  }
  // The domain cannot begin or end with a period.
  if (substr($subdomain, 0, 1) == '.') {
    $error_list[] = t('The domain must not begin with a dot (.)');
  }
  // The domain cannot begin or end with a period.
  if (substr($subdomain, -1) == '.') {
    $error_list[] = t('The domain must not end with a dot (.)');
  }
  // Check for valid characters
  $pattern = '/^[a-z0-9\.\+\-\*\?:]*$/i';
  if (!preg_match($pattern, $subdomain)) {
    $error_list[] = t('Only alphanumeric characters, dashes, and a colon are allowed.');
  }
  if (!empty($error_list)) {
    return t('The domain string is invalid:') . theme('item_list', $error_list);
  }
}
?>

Contact

  • agentrickard [at] gmail [dot] com

Donations

My Amazon.com Wish List