From 86ffb97c1c520cbb0eb74474485d263801523a33 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Sat, 23 Nov 2024 01:09:11 +0100 Subject: [PATCH] fix: phone regex --- .../ItaliaTheme/View/Commons/ContactLink.jsx | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/components/ItaliaTheme/View/Commons/ContactLink.jsx b/src/components/ItaliaTheme/View/Commons/ContactLink.jsx index 8a8ed7403..6b7544aab 100644 --- a/src/components/ItaliaTheme/View/Commons/ContactLink.jsx +++ b/src/components/ItaliaTheme/View/Commons/ContactLink.jsx @@ -33,23 +33,27 @@ const ContactLink = ({ tel, fax, email, label = true, strong = false }) => { const intl = useIntl(); const formatTel = (str, type) => - str.split(/\+?[0-9]( ?[0-9/-]+)+.?[0-9]*/gm).map((v, i) => - i % 2 === 0 ? ( - {` ${v} `} - ) : ( - - {v} - - ), - ); + str + .split( + /((?:\+?\d{1,3}[-.\s]?)?(?:\(?\d{3}\)?[-.\s]?)?\d{3}[-.\s]?\d{4})/gm, + ) + .map((v, i) => + i % 2 === 0 ? ( + {` ${v} `} + ) : ( + + {v} + + ), + ); const formatEmail = (str) => str