Skip to content

Commit

Permalink
fix: phone regex
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico committed Nov 23, 2024
1 parent 9c3a947 commit 86ffb97
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/components/ItaliaTheme/View/Commons/ContactLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
<span key={i}>{` ${v} `}</span>
) : (
<a
key={i}
href={`${type}:${v}`}
title={
type === 'tel'
? intl.formatMessage(messages.call)
: intl.formatMessage(messages.call_fax)
}
>
{v}
</a>
),
);
str
.split(
/((?:\+?\d{1,3}[-.\s]?)?(?:\(?\d{3}\)?[-.\s]?)?\d{3}[-.\s]?\d{4})/gm,
)
.map((v, i) =>
i % 2 === 0 ? (
<span key={i}>{` ${v} `}</span>
) : (
<a
key={i}
href={`${type}:${v}`}
title={
type === 'tel'
? intl.formatMessage(messages.call)
: intl.formatMessage(messages.call_fax)
}
>
{v}
</a>
),
);

const formatEmail = (str) =>
str
Expand Down

0 comments on commit 86ffb97

Please sign in to comment.