'/^\(\d{3}\)\s\d{3}-\d{4}(?:\sext\.\s\d{1,6})?$/', self::DOT_FORMAT => '/^\d{3}\.\d{3}\.\d{4}(?:\sext\.\s\d{1,6})?$/', ]; protected $_format = self::DOT_FORMAT; public function init() { $pattern = $this->_formatPatterns[$this->_format]; if (!$pattern) { throw new Qs_Exception('Unknown phone pattern.'); } $this->addValidator( 'regex', true, ['pattern' => $pattern, 'messages' => 'Phone number is in wrong format'] ); if (!$this->getFilter('Phone')) { $this->addFilter('Phone', [$this->_format]); } return $this; } public function setFormat($format) { if (!in_array($format, array_keys($this->_formatPatterns))) { throw new Qs_Exception('Unknown phone format.'); } $this->_format = $format; return $this; } public function getFormat() { return $this->_format; } public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return $this; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('ViewHelper') ->addDecorator('Phone') ->addDecorator('Errors') ->addDecorator('Description', ['tag' => 'p', 'class' => 'description']) ->addDecorator('HtmlTag', ['tag' => 'dd', 'id' => $this->getName() . '-element']) ->addDecorator('Label', ['tag' => 'dt']); } return $this; } }