Skip to content

Instantly share code, notes, and snippets.

@laudaikinhdi
Forked from fritsvt/YoutubeValidationRule
Created March 15, 2019 15:39
Show Gist options
  • Save laudaikinhdi/76da2eb321823f25ebc55dc04bee67fe to your computer and use it in GitHub Desktop.
Save laudaikinhdi/76da2eb321823f25ebc55dc04bee67fe 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