Skip to content

Instantly share code, notes, and snippets.

@atomicpages
Created January 24, 2013 09:37
Show Gist options
  • Select an option

  • Save atomicpages/4619196 to your computer and use it in GitHub Desktop.

Select an option

Save atomicpages/4619196 to your computer and use it in GitHub Desktop.

Revisions

  1. atomicpages created this gist Jan 24, 2013.
    15 changes: 15 additions & 0 deletions fbUrlCheck.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?php
    /**
    * A simple regex to test whether or not a facebook url is valid. For basic usage, this will do the job.
    * @see Test cases <http://ideone.com/ZMJp4f>
    */
    $fbUrlCheck = '/^(https?:\/\/)?(www\.)?facebook.com\/[a-zA-Z0-9(\.\?)?]/';
    $secondCheck = '/home((\/)?\.[a-zA-Z0-9])?/';

    $validUrl = 'https://www.facebook.com/atomicpages/';

    if(preg_match($fbUrlCheck, $validUrl) == 1 && preg_match($secondCheck, $validUrl) == 0) {
    echo 'Facebook URL is valid!';
    } else {
    echo 'Facebook URL is not valid!';
    }