Phone.php 948 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ q4rje+TEEVfnokuT7cbqT89kTV4MXBDWYGq+wyKH6pw=
  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. * phone number validator class
  14. */
  15. namespace Cube\Validate;
  16. class Phone extends AbstractValidate
  17. {
  18. protected $_message = "'%s' does not contain a valid phone number.";
  19. /**
  20. *
  21. * checks if the variable contains a valid phone number
  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. $value = str_ireplace(array('+', '-', ' ', '(', ')'), '', $value);
  32. if (is_numeric($value)) {
  33. return true;
  34. }
  35. return false;
  36. }
  37. }