regEx.php
Go to the documentation of this file.
1 <?php
6 namespace depage\htmlform\validators;
7 
11 class regEx extends validator
12 {
16  protected $regEx = "//";
17 
25  public function validate($value, $parameters = array())
26  {
27  $match = (bool) preg_match($this->regEx, $value, $matchedSubstring);
28 
34  $completeMatch = $match && ($value === $matchedSubstring[0]);
35 
36  if (preg_last_error() !== PREG_NO_ERROR) {
38  $this->log("Regular expression warning: error code " . preg_last_error());
39  }
40 
41  return $completeMatch;
42  }
43 
50  public function setRegEx($regEx)
51  {
52  $this->regEx = $regEx;
53  }
54 }
customizable validator for input elements
Definition: regEx.php:11
validate($value, $parameters=array())
validates value with regular expression
Definition: regEx.php:25
setRegEx($regEx)
sets the validators regular expression
Definition: regEx.php:50
$regEx
regular expression
Definition: regEx.php:16
parent validator class
Definition: validator.php:14
log($argument, $type)
error logging method
Definition: validator.php:88