-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9.x] New validation rules float
and float_between
#42522
Conversation
What about |
I would be very happy to swap the names of Let's talk about floats (really, floats)! Name The word Floats/decimals are more complicated than digits. If there would be a rule And if we are talking about In conclusion...
I'm willing to program all of this, of course, just give me a green light! 😉 |
Honestly I wonder if that dot change should just be reverted entirely. |
Do you actually need a new validation rule if you just combine the
|
@taylorotwell As I have already answered you, the validation rule $value = '0123';
$isValid = filter_var($value, FILTER_VALIDATE_INT) !== false; // false
Yes, please! |
Yeah, agree. Reverting it now. |
Validation rules
digits
anddigits_between
validated, well, digits. They worked perfectly fine since August 6, 2016, for more than 5 years… On January 5, 2022, a single person suddenly woke up and demanded that the rules should actually accept floats (to allow a dot between digits) and his wish was fulfilled the next day.Since nobody cares that floats are not actually digits and does not want to compromise, here are 2 "new" validation rules that validate floats (digits, but nobody cares about the difference, right?).
Currently, there are no other validation rules (or rule combinations) that can guarantee that the input contains only digits and that the input contains only a specific number of digits.
For example, with the "new" validation rules
float
andfloat_between
you can validate:float:4
passes0123
andfloat_between:4,8
passes01234567
)float:5
passes02421
)