You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
594B

  1. <?php
  2. namespace App\Rules;
  3. class SimpleRegEx extends BaseRule
  4. {
  5. /**
  6. * Create a new rule instance.
  7. *
  8. * @return void
  9. */
  10. public function __construct(private $pattern, private $message, private $notMatch = false)
  11. {
  12. //
  13. }
  14. public function check($value): bool
  15. {
  16. $match = preg_match($this->pattern, $value);
  17. return $this->notMatch ? $match === 0 : $match !== 0;
  18. }
  19. /**
  20. * Get the validation error message.
  21. *
  22. * @return string
  23. */
  24. public function message()
  25. {
  26. return $this->message;
  27. }
  28. }