lundi 8 avril 2019

Create Custom rule for Regex in Laravel

I have multiple forms(>20), I was looking for a validate the form input fields using Regex.

Insted of manually filling the regex to the validate in the controller, I would like to create a new rule and call the rull for the validation.

Just incase, if I need to update the regex pattern, I can do it in once place and dont have to do it in all the forms manually.

I am not sure how do I add the Regex pattern to the rules.

My steps:

php artisan make:rule MobileNo

My regex patterns,

For validating Phone no as well as land line no

`regex:/(^[0-9]+$)+/`

Validation for title:

regex:/(^[A-Za-z0-9@ ()%,:<>?*&-]+$)+/

Please guide me how do I acheive it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire