dimanche 24 janvier 2016

Laravel Regex Validation (text should end up with .jpg or .png)

I have a laravel validation rule something like this

public function rules(){
   return [
            'title' => 'required|max:100',
            'featured_image' => 'required|max:100|regex:(\d)+.(?:jpe?g|png|gif)',

        ];
}

I have a txt field where i dynamically add an image name, something like this (8123123123.jpg OR 234234234.png). If the text field doesn't have this pattern i want to show an error.

Now this regex does work in http://regexr.com/ but in laravel it doesn't. So basically it should look for digits as file name and should end with .jpg or .png

Any help is appreciated



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire