From 7c87c4716e1380989e78081ba9bec34446e38874 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 29 Dec 2013 21:17:27 +0100 Subject: [PATCH] Add regex validator --- include.forms.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include.forms.php b/include.forms.php index e951698..ad6b16c 100644 --- a/include.forms.php +++ b/include.forms.php @@ -245,6 +245,15 @@ class CPHPFormValidatorPromiseBaseClass return $this->next; } + public function ValidateRegex($key, $error_message, $pattern, $critical = false) + { + $this->next = new CPHPFormValidatorPromise($this, $this->handler, $key, array("pattern" => $pattern), "regex", $error_message, $critical, function($key, $value, $args, $handler){ + return preg_match($args["pattern"], $value) === 1; + }); + $this->next->handler = $this->handler; + return $this->next; + } + public function ValidateCustom($key, $error_message, $validator, $critical = false) { $this->next = new CPHPFormValidatorPromise($this, $this->handler, $key, array(), "custom", $error_message, $critical, $validator);