Skip to content

Commit

Permalink
Add verification if is a valid regex
Browse files Browse the repository at this point in the history
  • Loading branch information
JuGid committed Feb 9, 2021
1 parent 9e40768 commit 56f87af
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Validation/Rules/Library/RuleString.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ public function min(int $len): void

public function regexp(string $expr): void
{
if (!preg_match($expr, $this->value)) {
throw new RuleFailed(sprintf("string does not match regular expression %s", $expr));
}
if(@preg_match($expr, '') === FALSE) {
throw new RuleFailed(sprintf("regexp is not a valid regular expression %s", $expr));
}

if(!preg_match($expr, $this->value)) {
throw new RuleFailed(sprintf("string does not match regular expression %s", $expr));
}
}

public function url(): void
Expand Down

0 comments on commit 56f87af

Please sign in to comment.