Skip to content

Instantly share code, notes, and snippets.

@trung85
Forked from atomicpages/fbUrlCheck.php
Created September 12, 2017 08:47
Show Gist options
  • Save trung85/f7386ebfd591be07d71db90f8147e45b to your computer and use it in GitHub Desktop.
Save trung85/f7386ebfd591be07d71db90f8147e45b to your computer and use it in GitHub Desktop.
A simple facebook URL checker RegEx for PHP or JavaScript
<?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!';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment