1: <?php
2: /**
3: * Wei Framework
4: *
5: * @copyright Copyright (c) 2008-2015 Twin Huang
6: * @license http://opensource.org/licenses/mit-license.php MIT License
7: */
8:
9: namespace Wei\Validator;
10:
11: /**
12: * Check if the input is a natural number (integer that greater than or equals 0)
13: *
14: * @author Twin Huang <twinhuang@qq.com>
15: * @link http://en.wikipedia.org/wiki/Natural_number
16: */
17: class NaturalNumber extends BaseValidator
18: {
19: protected $invalidMessage = '%name% must be positive integer or zero';
20:
21: /**
22: * {@inheritdoc}
23: */
24: protected function doValidate($input)
25: {
26: if (false !== filter_var($input, FILTER_VALIDATE_INT) && $input >= 0) {
27: return true;
28: } else {
29: $this->addError('invalid');
30: return false;
31: }
32: }
33: }