-
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
[10.x] Allow digits
rules to work with decimal
#47976
Conversation
And what is wrong with decimal:3,3 and decimal:2,3? Are you more looking for allowing it cases like 12,345 or 123,45 but never 123,456? |
Hey @timacdonald, I was stumbling across the same issue, lately. Why did you close your PR? |
@buddhaCode, I can't remember exactly, but I believe there is already a way to do this with Laravel rules. |
Mhhh, I don't see any way to do this with existing rules in Laravel. Can you tell me, what way you have in mind? Dan linked my PR for Filament above my comment. Maybe you can have a look at it. And maybe you can resubmit your PR? Nether the less, I think a rule to validate the length before the dot would be a lot more practical in real use cases. I couldn't imagine a real use case, where the total length is important. |
@buddhaCode, I think I found that a combination of This example uses a class ExampleTest extends TestCase
{
/**
* @dataProvider data
*/
public function test_validation($expected, $value): void
{
$validator = Validator::make([
'value' => $value,
], [
'value' => 'max:99.999|decimal:0,3' // $table->decimal(5, 3)
]);
$this->assertSame($expected, $validator->passes());
}
public static function data()
{
return [
// lower boundary...
[true, 0.999 ],
[false, 0.9991],
// upper boundary...
[true, 99.999],
[false, 100.0],
];
}
} |
Oh thats a good solution. But I guess less obvious and less good readable than your PR. Also you need to have knowledge about the desired amount of decimal places. |
It is currently possible to limit the number of digits in an integer:
It is also currently possible to limit the number of digits after the decimal place in an decimal:
However, it is not possible to limit the total number of digits of a decimal. It would be useful to be able to specify the total number of digits.
Documented: laravel/docs#8943