Skip to content

Commit 476f920

Browse files
[8.x] Fix multiple dots for digits_between rule (#42330)
* Fix multiple dots for digits_between rule * wip * wip * wip * wip * Update ValidatesAttributes.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent abd5b38 commit 476f920

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,15 @@ public function validateDigitsBetween($attribute, $value, $parameters)
582582

583583
$length = strlen((string) $value);
584584

585+
if (((string) $value) === '.') {
586+
return false;
587+
}
588+
589+
// Make sure there is not more than one dot...
590+
if (($length - strlen(str_replace('.', '', (string) $value))) > 1) {
591+
return false;
592+
}
593+
585594
return ! preg_match('/[^0-9.]/', $value)
586595
&& $length >= $parameters[0] && $length <= $parameters[1];
587596
}

tests/Validation/ValidationValidatorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,24 @@ public function testValidateDigits()
22902290

22912291
$v = new Validator($trans, ['foo' => '0.9876'], ['foo' => 'digits_between:1,5']);
22922292
$this->assertTrue($v->fails());
2293+
2294+
$v = new Validator($trans, ['foo' => '1..2'], ['foo' => 'digits_between:1,10']);
2295+
$this->assertTrue($v->fails());
2296+
2297+
$v = new Validator($trans, ['foo' => '123.456.789'], ['foo' => 'digits_between:1,10']);
2298+
$this->assertTrue($v->fails());
2299+
2300+
$v = new Validator($trans, ['foo' => '...'], ['foo' => 'digits_between:1,10']);
2301+
$this->assertTrue($v->fails());
2302+
2303+
$v = new Validator($trans, ['foo' => '.'], ['foo' => 'digits_between:1,10']);
2304+
$this->assertTrue($v->fails());
2305+
2306+
$v = new Validator($trans, ['foo' => '.2'], ['foo' => 'digits_between:0,10']);
2307+
$this->assertTrue($v->passes());
2308+
2309+
$v = new Validator($trans, ['foo' => '2.'], ['foo' => 'digits_between:1,10']);
2310+
$this->assertTrue($v->passes());
22932311
}
22942312

22952313
public function testValidateSize()

0 commit comments

Comments
 (0)