From c7aa31dedd23674a84ccd4cc75a1daa56ad91e11 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Fri, 31 Jul 2015 20:44:04 +0200 Subject: [PATCH] (mvc) add basic validation to CSVListField type --- .../OPNsense/Base/FieldTypes/CSVListField.php | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php index 12c2a5365..6fec55f0a 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php @@ -54,6 +54,20 @@ class CSVListField extends BaseField */ private $selectOptions = array(); + /** + * @var string basic regex validation to use for the complete field + */ + protected $internalMask = '/^([\t\n\v\f\r 0-9a-zA-Z.,_\x{00A0}-\x{FFFF}])*/u'; + + /** + * set validation mask + * @param string $value regexp validation mask + */ + public function setMask($value) + { + $this->internalMask = $value ; + } + /** * retrieve data including selection options (from setSelectOptions) * @return array @@ -107,10 +121,19 @@ class CSVListField extends BaseField } /** - * @return array returns validators + * @return array returns regex validator */ public function getValidators() { - return array() ; + if ($this->internalValidationMessage == null) { + $msg = "list validation error" ; + } else { + $msg = $this->internalValidationMessage; + } + if (($this->internalIsRequired || $this->internalValue != null) && $this->internalMask != null) { + return array(new Regex(array('message' => $msg,'pattern'=>trim($this->internalMask)))); + } else { + return array(); + } } }