Originally published at: Beware When Pasting Phone Numbers Copied from Contacts - TidBITS
It turns out that Contacts on the Mac stores extra invisible characters with every phone number, which can cause trouble when copying and pasting them into some online forms. Here’s what’s going on and how to work around the problem.
Originally published at: Beware When Pasting Phone Numbers Copied from Contacts - TidBITS
I so wish I had read this a couple hours ago. I literally just had this problem, and ended up typing my numbers all in manually, because every pasted number failed. At the time, I thought it was just an extra space I missed seeing or maybe a wrong hyphen (minus character instead). In any case, it’s good to know this going forward! Thanks for explaining this.
Unfortunately, Apple is in a no-win situation here.
If they just copy the text, then people trying to paste the number into a block of right-to-left text will end up with display problems
If a phone number was just numbers (e.g. 5551234567), then it wouldn’t be a problem. Numbers are “weak” characters in Unicode, meaning they will always render in their correct direction (left-to-right) for European numbers, but will not change the direction of the surrounding text. Similarly, hyphens are weak characters, so “555-123-4567” would also render correctly.
But spaces, for example, are “neutral” characters. They operate based on the direction of the surrounding text. So a phone number consisting of “555 123 4567”, when pasted into right-to-left text would be presented as “4567 123 555”. Each sequence of weak characters (the digits) is left-to-right, but the neutral space characters presents each block of digits as right-to-left when they are in a block of right-to-left text.
There are additional, even more complicated rules when there are matched-bracket-pairs (e.g. parentheses) in the text.
The only way to avoid this mess when pasting phone numbers (which may have a virtually infinite mix of weak characters, neutral characters and bracket-pairs) into right-to-left text is to use the left-to-right override, to ensure that the entire sequence will always be presented as left-to-right text.
So Apple must choose between breaking web forms (where the web designer really should be filtering out these characters anyway) or breaking the ability to paste into some documents, which will probably result in just as many problems and would probably require the same solution (to manually re-type the number).
But wouldn’t the suggestion of having this happen only when the user has RTL languages enabled on the Mac resolve it? It feels like the sort of thing that doesn’t need to be the same for everyone.
Enabled in what way? To simply have the fonts installed? To have a keyboard configured? To be running macOS’s UI in that language? What about the ability to enable languages on a per-app basis?
For example, I can view and edit a Japanese document, even though I don’t have the language installed. I can’t type the characters without adding the keyboard and input method, but I can copy/paste text in both directions without them.
In general, this is a pretty complicated issue.
This might be solvable via the clipboard - include the characters for Unicode text, but strip them from Plain text content. And it might even do that already. But then you still need the web browser to use the plain-text version when pasting into forms. Which could be a problem for other fields (e.g. a name or address, where international characters may be required).
I think ultimately, browsers may need to add a “paste special” command, or some equivalent. I know that when I use Microsoft Outlook on my Windows PC, the editor is a subset of the Microsoft Word editor. I can type Ctrl-V to paste formatted text, but Ctrl-Shift-V to paste the text without formatting. Something like that in a web browser for entering text in forms might be a workaround, but only if users actually try it.
Heck, phone numbers are even hard to enter manually in many web forms. The designer tries to outsmart users by automatically adding (or not) hyphens and parentheses, and so on. It’s almost as frustrating as entering two-letter abbreviations for States. (And, as Adam noted, a pox on those programmers who don’t use a strip() function to remove starting and trailing spaces.)
I’ve been thinking about this further and David C. is correct this is not a simple problem.
Paste as Plain Text doesn’t work because you may want to paste plain, unstyled phone numbers into Hebrew Text.
My spiffy little Keyboard Maestro macro doesn’t work because most people don’t have KM and won’t remember the problem well enough to find the macro in the menu and they really won’t remember it when they’re so frustrated they can’t buy that present for Aunt Marge instantly.
What occurs to me is to make the characters visible in Contacts and in web forms. It’s yet another layer of display logic to program (show kinky doodad when encountering U+202C, etc. and replace with original when copying) but by having it visible and the phone number fails validation the average user will then say, “What’re those strange things? I’ll just copy the number itself…” You could do all sorts of nifty & weird stuff like making things like leading and trailing whitespace obvious.
Apple designers would be horrified at this desecration of visual simplicity but you know? Sometimes simplicity means being obvious.
Trust me, I have written hundreds of regular expressions to recognize international phone numbers in text flows and the variety is boggling. Better to give the user a simple way to make sure Aunt Marge’s proper phone number gets into that order form.
So it’s not a problem that Contacts is the only place in the UI where you can’t select some displayed text, do a standard Copy, and not be able to do a standard Paste of the same displayed text elsewhere?
If the user doesn’t see these invisible markers, he definitely doesn’t want to copy them with the text. This is a “gotcha” for most users that doesn’t “just work.”
I’m with @schwartz - I want nothing added to that field that I didn’t type in the first place when I created the contact. In fact, if Apple is going to be smart about it, I’d just want them to strip out any white space and paste in everything else. If it causes too many characters to be pasted in, I’ll deal with it manually and curse the web form designer.
I would phrase it as the designer frustrates the user by assuming that the user will know what format the designer uses and therefore there is no need to state what format the form expects. It cannot be that hard to state what format to use. And when a form wants a Social Security number or a phone number spread over three fields, it seems to me that the insertion point should move to the next field rather than requiring tab. And I have come across forms that require a click because they do not accept tab.
No extra characters for me, on Big Sur. Maybe a Monterey or Ventura problem?
No extra characters for me in Ventura. I copied several telephone numbers, pasted them in BBEdit and no extraneous character was found.
On my systems (one running Sierra, one Big Sur), I have found that some contacts include these symbols and some do not. And (problematically, IMO), some don’t include the terminating pop-directional-formatting character. And the left-to-right-override isn’t always the first character. (e.g. when my number begins with a
+1 , the override appears between the
+1 and the area code.)
So it may not be the contacts app itself, but a function of what app was used to create the contacts. Mine come from iCloud and my Google contacts, and both sets have contacts added through a variety of mechanisms over the years, including:
- Entered via the Contacts app (and Address Book before that) on all versions of Mac OS since the app was invented (and before there was an iCloud).
- Entered via Google’s web interface for its contacts
- Entered via various mail apps that offer integration with contacts apps (whether the Mac API or via LDAP/CardDav) on Mac, Windows and Linux systems
- Entered via mobile contacts app on both iOS and Android
- Imported via vCard objects and all kinds of apps and web sites
Unfortunately, it is pretty much impossible for me to remember how I created all those contacts after over 20 years.
I just had this type of oddity a few days ago when trying to paste a phone number from Contacts into a new email. I then tried pasting the number back into Contacts over the old number, and it inserted odd spaces in inappropriate places. The only way to repair the damage was to delete the original phone number entry, create a new one, and manually type the number back.
But what occurs to me is the “original” number that was (invisibly) incorrectly formatted in Contacts was placed there as a copy and paste from a received Apple Mail email. It was part of a (business) Signature of that email. Maybe this is a common cause for this issue?
I just submit this as a data point for possible consideration by others who have encountered this bug.
BBEdit doesn’t show those characters in a regular text window (even with Show Invisibles turned on). If you do a Hex Dump of the file you’ll see them.
Really the best way to check is to paste the phone number into a Terminal window.
I see it now. Thanks for the tip!
I used to do a lot of international calling, and this is not an exaggeration. To make it worse, the way phone numbers are written on web sites or in emails typically does not include codes for international calling, so you have to know how to make international calls from whatever country you are in. Add another layer of complication if you’re using a calling card which has its own codes. And just to complicate things further, small countries may not have ten-digit standards for phone numbers. If you’re trying to pick up numbers from caller IDs, some phone systems here in the US do not include the area code in calls within the same area code, and show only the last seven digits.
With such divergent standards, the more you try to automate in processing, the more things are going to go wrong. When I try to return a call from within my area code by using automatic call-back, it doesn’t work if the caller ID gives only 7 digits because the phones expect the full 10 digits.
Suggest NOT to include your e-mail address or phone number (what ever format +/- extra characters) here or any forum. Bots will find it, copy it, try to link it to your name, and sell it. Suggest to edit your post and remove it as soon as possible.
I use several mail addresses, including one one for sites that are almost guaranteed I will get spam. Incredible as it may seem, at this address, which I have been using for 12 years, and only use for some mail lists, I have never received a single spam mail (hope tomorrow it won’t start).
But I will do as you sugest.
If you use the Text → “Zap Gremlins…” → Replace with code → Use ASCII equivalent
they will show up .