Source of file RegexTextField.php
Size: 1,082 Bytes - Last Modified: 2021-12-23T10:25:15+00:00
/var/www/docs.ssmods.com/process/src/src/Forms/RegexTextField.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 | <?php namespace Symbiote\Addressable\Forms; use SilverStripe\Forms\TextField; /** * A text field that validates that its contents match a regular expression. * * @package silverstripe-addressable */ class RegexTextField extends TextField { protected $regex; public function Type() { return 'regextext text'; } /** * @return string */ public function getRegex() { return $this->regex; } /** * @param string $regex */ public function setRegex($regex) { $this->regex = $regex; } public function validate($validator) { if ($this->value && $this->regex) { if (!preg_match($this->regex, $this->value)) { $name = $this->Title() ? $this->Title() : $this->name; $message = _t('RegexTextField.VALIDATE', 'Please enter a valid format for "%s".'); $validator->validationError($this->name, sprintf($message, $name), 'validation'); return false; } } return true; } } |