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 decimal
13: *
14: * @author Twin Huang <twinhuang@qq.com>
15: */
16: class Decimal extends BaseValidator
17: {
18: protected $invalidMessage = '%name% must be decimal';
19:
20: protected $negativeMessage = '%name% must not be decimal';
21:
22: /**
23: * {@inheritdoc}
24: */
25: protected function doValidate($input)
26: {
27: if (is_float($input) || (is_numeric($input) && count(explode('.', $input)) == 2)) {
28: return true;
29: }
30:
31: $this->addError('invalid');
32: return false;
33: }
34: }
35: