depage-forms v1.4.1
html forms made easy
Loading...
Searching...
No Matches
RegEx.php
Go to the documentation of this file.
1<?php
2
7
8namespace Depage\HtmlForm\Validators;
9
13class RegEx extends Validator
14{
18 protected $regEx = "//";
19
27 public function validate($value, $parameters = [])
28 {
29 $match = (bool) preg_match($this->regEx, $value, $matchedSubstring);
30
36 $completeMatch = $match && ($value === $matchedSubstring[0]);
37
38 if (preg_last_error() !== PREG_NO_ERROR) {
40 $this->log("Regular expression warning: error code " . preg_last_error());
41 }
42
43 return $completeMatch;
44 }
45
52 public function setRegEx($regEx)
53 {
54 $this->regEx = $regEx;
55 }
56}
customizable validator for input elements
Definition RegEx.php:14
$regEx
regular expression
Definition RegEx.php:18
validate($value, $parameters=[])
validates value with regular expression
Definition RegEx.php:27
setRegEx($regEx)
sets the validators regular expression
Definition RegEx.php:52
log($argument, $type)
error logging method
Definition Validator.php:89