Created
June 16, 2018 16:39
-
-
Save fritsvt/38d5043e7eb883cb3ea3a148de5f9fd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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