I was looking for a decent way to validate against a domain name (not a url) but could not see one in either Drupal or Codeigniter so I quickly built this function
/** * function to check for valid domain names */ function validate_domain_name($domain) { // Strip out any http or www $search = array('http://', 'www.'); $replace = array('',''); $domain = str_replace($search, $replace, $domain); $regex = "/^([a-z0-9][a-z0-9\-]{1,63})\.[a-z\.]{2,6}$/i"; return preg_match($regex, $domain, $matches); }
Happy coding !!!