Alphanumeric.php 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ x+PfE2Qr7w06g/wuPdrrdIeoXM2b1v9v02sKO8kGVQc=
  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. * alphanumeric only validator class
  14. * space character is not allowed since version 1.2
  15. */
  16. namespace Cube\Validate;
  17. class Alphanumeric extends AbstractValidate
  18. {
  19. protected $_message = "'%s' must contain an alphanumeric value.";
  20. /**
  21. *
  22. * checks if the variable contains an alphanumeric value
  23. *
  24. * @return bool return true if the validation is successful
  25. */
  26. public function isValid()
  27. {
  28. $value = $this->getValue();
  29. if (empty($value)) {
  30. return true;
  31. }
  32. if (!preg_match('#^[0-9a-zA-Z\_\-]+$#', $value)) {
  33. return false;
  34. }
  35. return true;
  36. }
  37. }