diff --git a/README.md b/README.md index 0acca86..12598f5 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,7 @@ $this->assertTrue($v->validate()); * `different` - Field must be different than another field * `accepted` - Checkbox or Radio must be accepted (yes, on, 1, true) * `numeric` - Must be numeric + * `integerType` - Must be integer type * `integer` - Must be integer number * `boolean` - Must be boolean * `array` - Must be array diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index 9b83cec..dc3ba79 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -269,6 +269,19 @@ protected function validateInteger($field, $value, $params) return filter_var($value, \FILTER_VALIDATE_INT) !== false; } + /** + * Validate that a field is an integer type + * + * @param string $field + * @param mixed $value + * @param array $params + * @return bool + */ + protected function validateIntegerType($field, $value, $params) + { + return is_int($value); + } + /** * Validate the length of a string * diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index d6e6dd3..6461bac 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -294,6 +294,24 @@ public function testNumericInvalidAltSyntax() $this->assertFalse($v->validate()); } + public function testIntegerTypeValid() + { + $v = new Validator(array('num' => 10)); + $v->rule('integerType', 'num'); + $this->assertTrue($v->validate()); + + $v = new Validator(array('num' => -10)); + $v->rule('integerType', 'num'); + $this->assertTrue($v->validate()); + } + + public function testIntegerTypeNotValid() + { + $v = new Validator(array('num' => '10')); + $v->rule('integerType', 'num'); + $this->assertFalse($v->validate()); + } + public function testIntegerValid() { $v = new Validator(array('num' => '41243'));