Posted By

jprochazka on 10/02/10


Tagged

validation


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

cjmling
bobbym245
melik
voove


Validate a domain name.


 / Published in: PHP
 

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

  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  

You need to login to post a comment.