Skip to content

Commit

Permalink
feat(NumberRule): remove space like a thousand delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Jan 30, 2025
1 parent 00a938f commit 6912007
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Validation/Rules/NumberRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class NumberRule implements Rule
{
public function passes($attribute, $value): bool
{
if (is_string($value)) {
$value = preg_replace('/\s+/', '', $value);
}

if (self::isNumericInt($value)) {
$intVal = (int) $value;
return $intVal !== PHP_INT_MAX && $intVal !== PHP_INT_MIN;
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/Validation/Rules/NumberRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ protected function testData(): array
return [
new RuleExpectation('test', false),
new RuleExpectation('234', true),
new RuleExpectation(" - 1\t234. 065 ", true),
new RuleExpectation(' 1 234. 065 ', true),
new RuleExpectation('-234', true),
new RuleExpectation(234, true),
new RuleExpectation(-234, true),
Expand Down Expand Up @@ -47,6 +49,7 @@ protected function testData(): array
new RuleExpectation('-,', false),
new RuleExpectation('.', false),
new RuleExpectation('', false),
new RuleExpectation(null, false),
new RuleExpectation('9223372036854775807', false),
new RuleExpectation('9223372036854775807.5', false),
new RuleExpectation('922337203685477580703434355.5', false),
Expand Down

0 comments on commit 6912007

Please sign in to comment.