Skip to content

Instantly share code, notes, and snippets.

@fritsvt
Created June 16, 2018 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fritsvt/38d5043e7eb883cb3ea3a148de5f9fd2 to your computer and use it in GitHub Desktop.
Save fritsvt/38d5043e7eb883cb3ea3a148de5f9fd2 to your computer and use it in GitHub Desktop.
// Make sure to put this at the top of your AppServiceProvider: use Illuminate\Support\Facades\Validator;
Validator::extend('youtube', function ($attribute, $value, $parameters, $validator) {
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $value, $matches);
return count($matches) > 0;
}, "Sorry, this doesn't look like a valid youtube URL");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment