コード例 #1
0
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     $originalPhone = $this->phone;
     $originalExtension = $this->extension;
     $phone = preg_replace('/[^0-9a-zA-Z]/', '', $originalPhone);
     preg_match('/([0-9]+)([a-zA-Z]*)([0-9]*)/', $phone, $matches);
     $this->phone = isset($matches[1]) ? $matches[1] : null;
     if (empty($originalExtension) || isset($matches[3]) && $originalExtension === $matches[3]) {
         $this->extension = isset($matches[3]) ? $matches[3] : null;
     } else {
         unset($matches[0]);
         $this->phone = trim(implode(' ', $matches));
     }
     if (empty($this->phone)) {
         $this->phone = null;
     }
     if (empty($this->extension)) {
         $this->extension = null;
     }
     return parent::beforeValidate();
 }