Skip to content

Instantly share code, notes, and snippets.

@haohcraft
Created May 15, 2014 18:01
Show Gist options
  • Save haohcraft/4713d0cee2431007b15c to your computer and use it in GitHub Desktop.
Save haohcraft/4713d0cee2431007b15c to your computer and use it in GitHub Desktop.
var urlRegEx = /(http|https|ftp):\/\/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?$&\/\/=]*)?/gi;
//If entered data doesn't match the URL regex, then return error data, and don't actually make the AJAX request.
if (!urlRegEx.test(link)) {
var badURL = {warning: "Snap! That link came back with nothing. How about pasting it in?", tags: []};
$scope.suggestedData = badURL;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment