Created
December 7, 2012 23:23
-
-
Save mikefowler/4237479 to your computer and use it in GitHub Desktop.
Link validation class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Coffeescript + Underscore syntactic sugar makes this so gracefully concise. | |
| # | |
| class LinkValidation | |
| constructor: -> | |
| @VALID_SERVICES = [ | |
| "flickr.com\/photos\/[a-z0-9_-]+\/(\d+)" | |
| "soundcloud\.com\/((?!tags)[a-z0-9]+)\/((?!likes|following|followers|comments|groups)[a-z0-9_-]+)" | |
| ] | |
| # Given any URL, determine if it's valid based on the expressions defined above | |
| validate: (url)-> | |
| !!(_.find @VALID_SERVICES, (service) -> url.match(service)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment