Numeric.php 881 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ i6MI1E7m1QlY3549V4YAhWpxUzXq36zNHnSc6afL//Q=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2017 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.10 [rev.1.10.01]
  11. */
  12. /**
  13. * numeric only validator class
  14. */
  15. namespace Cube\Validate;
  16. class Numeric extends AbstractValidate
  17. {
  18. protected $_message = "'%s' must contain a numeric value.";
  19. /**
  20. *
  21. * checks if the variable contains a numeric value
  22. *
  23. * @return bool return true if the validation is successful
  24. */
  25. public function isValid()
  26. {
  27. $value = $this->getValue();
  28. if (empty($value)) {
  29. return true;
  30. }
  31. if (!preg_match('#^-?\d*\.?\d+$#', $value)) {
  32. return false;
  33. }
  34. return true;
  35. }
  36. }