Skip to content

Instantly share code, notes, and snippets.

@bengitiger
Forked from fritsvt/YoutubeValidationRule
Created January 9, 2019 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bengitiger/de82a420e95707cf958eeb5db860f5c2 to your computer and use it in GitHub Desktop.
Save bengitiger/de82a420e95707cf958eeb5db860f5c2 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