1

I have a number filed, I need to make a custom validation for it like this

He can not write a number without put at the beginning of number one of these number

077 | 075 | 078 | the number must be like this 07701231231

2 Answers 2

1

I think the starts_with validation rule fits your needs here:

https://laravel.com/docs/8.x/validation#rule-starts-with

Since 077, 075 and 078 are not valid integer values (would convert to 77, 75, and 78), you'd use the following rule and handle that as a string:

'number' => 'string|starts_with:077,078,075'
Sign up to request clarification or add additional context in comments.

Comments

0

There are many ways to do so, one of them (accepted answer) is to use starts_with validation, another one is to use regex validation, here is the code for the regex validation:

'number' => 'string|regex:/^(077|075|078)\d+$/'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.