My app opens WhatsApp with a wa.me link, and the link needs the phone number in international format: digits only, with the country code at the front. The first version of my function removed spaces and symbols and did nothing else.
Italian mobile numbers start with 3, so a customer saved as "333 1234567" turned into wa.me/3331234567, and WhatsApp reads the first digits as a country code. 33 is France. A number starting with 340 reads as 34, which is Spain, and one starting with 320 reads as 32, which is Belgium. The message that goes out carries the customer's name, her dog's name and the salon's name, and it would have landed with a stranger.
I never noticed, because every number I had typed during development started with +39. The reviewer fed the function twenty different inputs. The ones written with +39, 0039 or 39 in front worked. A landline like "091 6111222" came out as a link that was not valid, and "12345" came out as a link too. Even "abc" produced one, an empty link. Nothing in the old function could say no.
The new function brings every number to international format. A mobile number that starts with 3 gets the prefix 39, and so does a landline that starts with 0. Anything it cannot recognize is refused, and the send button checks that before the state of the offer changes. The same normalized number feeds the exclusion list, which means a customer who asks to be removed stays removed even if a later file writes her number with a space, a dash or a +39.
The twenty inputs are now a test, and I added a few numbers from my own contact list that I had never thought to try.
What I keep from this is a habit: data from a file or a form gets normalized once, at the door, and the app uses that single form everywhere afterwards.

