Skip to content

Commit 5a3e7be

Browse files
Nullable para valores numericos.
1 parent f9e1ac3 commit 5a3e7be

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/ValidationRules/NumericValidation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use ArrayUtils\ValidationRule;
1212

1313
class NumericValidation implements ValidationRule {
14+
private $allowNull = false;
1415

1516
/**
1617
* @return string
@@ -25,7 +26,7 @@ public function getIdentifier() {
2526
* @return array
2627
*/
2728
public function validate($value) {
28-
if (!is_numeric($value)) {
29+
if (($value === null && !$this->allowNull) || !is_numeric($value)) {
2930
return array("Campo não é numérico.");
3031
}
3132

@@ -36,5 +37,6 @@ public function validate($value) {
3637
* @param mixed $params
3738
*/
3839
public function setParams($params) {
40+
$this->allowNull = isset($params[0]) && $params[0] == "nullable";
3941
}
4042
}

0 commit comments

Comments
 (0)