Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ public function validateDecimal($attribute, $value, $parameters)

$matches = [];

if (preg_match('/^[+-]?\d*\.?(\d*)$/', $value, $matches) !== 1) {
if (preg_match('/^[+-]?\d*\.?(\d*)$/', (string) $value, $matches) !== 1) {
return false;
}

Expand Down Expand Up @@ -1699,7 +1699,7 @@ public function validateMaxDigits($attribute, $value, $parameters)

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

return ! preg_match('/[^0-9]/', $value) && $length <= $parameters[0];
return ! preg_match('/[^0-9]/', (string) $value) && $length <= $parameters[0];
}

/**
Expand Down Expand Up @@ -1809,7 +1809,7 @@ public function validateMinDigits($attribute, $value, $parameters)

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

return ! preg_match('/[^0-9]/', $value) && $length >= $parameters[0];
return ! preg_match('/[^0-9]/', (string) $value) && $length >= $parameters[0];
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3256,13 +3256,25 @@ public function testValidateMaxDigitsDoesNotThrowOnNonStringValue()
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => ['array']], ['x' => 'max_digits:5']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['x' => 123], ['x' => 'max_digits:5']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => 123456], ['x' => 'max_digits:5']);
$this->assertFalse($v->passes());
}

public function testValidateMinDigitsDoesNotThrowOnNonStringValue()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => ['array']], ['x' => 'min_digits:1']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['x' => 123], ['x' => 'min_digits:2']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => 1], ['x' => 'min_digits:2']);
$this->assertFalse($v->passes());
}

public function testValidateDoesntStartWith()
Expand Down Expand Up @@ -3718,6 +3730,12 @@ public function testValidateDecimal()
$this->assertTrue($v->passes());
$v = new Validator($trans, ['foo' => '123.34'], ['foo' => 'Decimal:0,2']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => 123], ['foo' => 'Decimal:0']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => 1.23], ['foo' => 'Decimal:0,3']);
$this->assertTrue($v->passes());
}

public function testValidateInt()
Expand Down
Loading