Url.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ CXDHlInlrvmyqFCA1iYWVGyijIcOwxeEZp6enK5w9rc=
  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. * url validator class
  14. */
  15. namespace Cube\Validate;
  16. class Url extends AbstractValidate
  17. {
  18. protected $_message = "'%s' does not contain a valid URL.";
  19. /**
  20. *
  21. * checks if the variable contains a valid url
  22. * the url needs to end with a forward slash to be considered valid
  23. * example:
  24. * http://site.com/ - valid
  25. * http://www.site.com/ - valid
  26. * http://www.site.com - invalid
  27. *
  28. * @return bool return true if the validation is successful
  29. */
  30. public function isValid()
  31. {
  32. $value = $this->getValue();
  33. if (empty($value)) {
  34. return true;
  35. }
  36. if (!preg_match('#^\S+://\S+$#', $value)) {
  37. return false;
  38. }
  39. return true;
  40. }
  41. }