Tricky12
Tricky12

Reputation: 6822

Mobile telephone detection creates links on other numbers, such as zip codes

I am trying to get telephone styling/highlighting working in mobile for current iOS and Android devices. It works fine for telephone numbers, but it also treats other numbers the same (makes them clickable links that open up the phone dialer). These include zip codes and other numbers that should not be treated as phone numbers. I am aware that you can disable this functionality completely using the meta tag below:

<meta name="format-detection" content="telephone=no">

However, I want the functionality, just ONLY on phone numbers.

I also am aware that you can disable this and then add links around all phone numbers using "tel:x-xxx-xxx-xxxx", but that seems really tedious and I was hoping to find a better solution (if there is one).

Upvotes: 1

Views: 820

Answers (2)

Tricky12
Tricky12

Reputation: 6822

I found that the best solution (for me) is to keep this enabled, by not having the meta tag, and just manually fixing the "mistaken links" that are created. Since I only care about supporting iOS and Android, the current versions at that, it was easiest to go through and fix the few numbers that were being linked as phone numbers. I tried @Jukka's suggestion with &nbsp; but found that it added the undesired space, so I found that &shy; (soft hyphen) was the best route to go.

Example:

If you have any kind of account number that is 7+ numbers long, it will be considered a phone number.

1234567 - Appears as a phone number
1234567&shy; - Does not appear as a phone number

Note that these were only tested in current iOS and Android operating systems.

Upvotes: 0

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201538

The telephone number recognition is rather primitive and even erroneous, so it is perhaps best switched off, using the method mentioned. For example, the Android 4 browser does not recognize my phone number in the standard international format (it ignores the country prefix and operator code, when spaces are used).

But if you wish to make use of it and still switch it off for other numeric strings, then the following observation might be useful: The Android browser seems to treat a sequence of seven or more digits (e.g., 1234567) as a phone number, if a single space character intervenes. It does not work that way if there is no space (1234567) or if there is more than one space (1 234 567) or if there is an intervening hyphen (123-4567). A no-break space is not taken as a space, so the following would not be recognized: 123&nbsp;4567.

I’m afraid this is not consistent across browsers that have such features.

Upvotes: 1

Related Questions