Skip to content

Commit 86ffb97

Browse files
committed
fix: phone regex
1 parent 9c3a947 commit 86ffb97

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/components/ItaliaTheme/View/Commons/ContactLink.jsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,27 @@ const ContactLink = ({ tel, fax, email, label = true, strong = false }) => {
3333
const intl = useIntl();
3434

3535
const formatTel = (str, type) =>
36-
str.split(/\+?[0-9]( ?[0-9/-]+)+.?[0-9]*/gm).map((v, i) =>
37-
i % 2 === 0 ? (
38-
<span key={i}>{` ${v} `}</span>
39-
) : (
40-
<a
41-
key={i}
42-
href={`${type}:${v}`}
43-
title={
44-
type === 'tel'
45-
? intl.formatMessage(messages.call)
46-
: intl.formatMessage(messages.call_fax)
47-
}
48-
>
49-
{v}
50-
</a>
51-
),
52-
);
36+
str
37+
.split(
38+
/((?:\+?\d{1,3}[-.\s]?)?(?:\(?\d{3}\)?[-.\s]?)?\d{3}[-.\s]?\d{4})/gm,
39+
)
40+
.map((v, i) =>
41+
i % 2 === 0 ? (
42+
<span key={i}>{` ${v} `}</span>
43+
) : (
44+
<a
45+
key={i}
46+
href={`${type}:${v}`}
47+
title={
48+
type === 'tel'
49+
? intl.formatMessage(messages.call)
50+
: intl.formatMessage(messages.call_fax)
51+
}
52+
>
53+
{v}
54+
</a>
55+
),
56+
);
5357

5458
const formatEmail = (str) =>
5559
str

0 commit comments

Comments
 (0)