Skip to content

Instantly share code, notes, and snippets.

@mikefowler
Created December 7, 2012 23:23
Show Gist options
  • Select an option

  • Save mikefowler/4237479 to your computer and use it in GitHub Desktop.

Select an option

Save mikefowler/4237479 to your computer and use it in GitHub Desktop.
Link validation class
#
# 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