Digits.php 876 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ IhS0obfuyVroCfh4+I48qXA/qqiB9Uq2WgEUR41GqlE=
  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. * digits only validator class
  14. */
  15. namespace Cube\Validate;
  16. class Digits extends AbstractValidate
  17. {
  18. protected $_message = "'%s' can only contain digits.";
  19. /**
  20. *
  21. * checks if the variable contains digits only
  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('#^-?[0-9]+$#', $value)) {
  32. return false;
  33. }
  34. return true;
  35. }
  36. }