diff --git a/vendor/magento/module-customer/Model/Validator/Telephone.php b/vendor/magento/module-customer/Model/Validator/Telephone.php index 0c85cb51f7e3d..22394e6585653 100644 --- a/vendor/magento/module-customer/Model/Validator/Telephone.php +++ b/vendor/magento/module-customer/Model/Validator/Telephone.php @@ -7,7 +7,7 @@ namespace Magento\Customer\Model\Validator; -use Magento\Customer\Model\Customer; +use Magento\Customer\Model\Address; use Magento\Framework\Validator\AbstractValidator; /** @@ -21,21 +21,24 @@ class Telephone extends AbstractValidator * \() :Matches open and close parentheses * \+: Matches the plus sign. * \-: Matches the hyphen. + * \.: Matches the dot character (e.g. 06.76.40.32.22) + * \/: Matches the forward slash (e.g. +43680/2149568) * \d: Digits (0-9). + * \s: Matches whitespace characters. */ - private const PATTERN_TELEPHONE = '/(?:[\d\s\+\-\()]{1,20})/u'; - + private const PATTERN_TELEPHONE = '/^[\d\s+().\/ -]{1,20}$/u'; + /** * Validate telephone fields. * - * @param Customer $customer + * @param \Magento\Customer\Model\Address $value * @return bool */ - public function isValid($customer) + public function isValid($value): bool { - if (!$this->isValidTelephone($customer->getTelephone())) { + if (!$this->isValidTelephone((string)$value->getTelephone())) { parent::_addMessages([[ - 'telephone' => "Invalid Phone Number. Please use 0-9, +, -, (, ) and space." + 'telephone' => "Invalid Phone Number. Please use 0-9, +, -, (, ), ., / and space." ]]); } @@ -48,12 +51,10 @@ public function isValid($customer) * @param string|null $telephoneValue * @return bool */ - private function isValidTelephone($telephoneValue) + private function isValidTelephone(?string $telephoneValue): bool { if ($telephoneValue != null) { - if (preg_match(self::PATTERN_TELEPHONE, (string) $telephoneValue, $matches)) { - return $matches[0] == $telephoneValue; - } + return preg_match(self::PATTERN_TELEPHONE, $telephoneValue) === 1; } return true;