Description |
Validating a Facebook page can be a little bit tricky. This is because there are two valid formats. The first is facebook.com/pages/USERNAME/numbers/, the second is designed for big business which grants them a clean url such as facebook.com/coca-cola/. I see this regex being used in a user profile admin page and I think it does a good enough job for this purpose. The problem is bad urls could slip through which meet the criteria for the clean facebook page url but aren't in valid pages on the site.
The main example being that an incomplete numbered url could slip through as http://www.facebook.com/pages/ would validate. Facebook also uses various subdomains such as en-gb.facebook.com to provide localised versions of the site. This regex will accept a prefix of either www or a locale code of two letters dash two letters. It doesn't validate the actual country code though.
[UPDATED] Added full stop to list of valid characters for page names. |