Validate a Domain Name

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 !!!

Post your comment


No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments

Copywrite © 2017 Kevin Phillips All rights are reserved.

Proudly supporting opensource software