Validate a domain name.


/ Published in: PHP
Save to your folder(s)

The following function validates and returns TRUE or FALSE if the supplied string could be a valid domain name format.


Copy this code and paste it in your HTML
  1. <?php
  2. function validUrl($url) {
  3. if (preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $url)) {
  4. return TRUE;
  5. else
  6. return FALSE;
  7. }
  8. }
  9. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.