Skip to content

Instantly share code, notes, and snippets.

@ThienTranDuy
Last active February 1, 2020 09:24
Show Gist options
  • Save ThienTranDuy/d6e52b20e407813ffcfdf57f1bf00192 to your computer and use it in GitHub Desktop.
Save ThienTranDuy/d6e52b20e407813ffcfdf57f1bf00192 to your computer and use it in GitHub Desktop.
YoutubeValidationRule
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