1

We have defined some rules in laravel but we need rule in which length of string should not be 5.

code is given below.

$rules = array(
'id' => 'required|numeric|digits_between:7,8'
);

current rule is length would be in between 7 and 8 but i need to modify it to length should be anything but not equal to 5. Please help to resolve.

2
  • I can't find something like that in the documentation. You can create a custom validator to solve this. Commented Aug 12, 2022 at 12:52
  • So it can be any number other than 5? Commented Aug 12, 2022 at 12:52

1 Answer 1

0

Never forget regexs :) Here is an example that prevents length =5, not_regex is used cause d{} cant be negated so i consider this the optimal and shortest solution

 'id' =>'required|not_regex:/\b\d{5}\b/',

hope it helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.