3 ms·
Probably the best approach is not using any pattern at all. The less you force your users into something that will not work most of the times, the best. I alway
by DeusExMachina 17y ago
Probably the best approach is not using any pattern at all. The less you force your users into something that will not work most of the times, the best. I always struggle to input information even in forms designed specifically for my country.
Just let people enter numbers with all the spaces and the dashes the wish. After all, if a human will ever need a phone number, he will be able to read it in any form. If these characters are a problem for you to store, simply strip them. The routine to do this takes the same effort to write as the one to check the input.
- weavejester 17y agoIt's curious how many forms do not allow spaces and dashes in numerical data like phone numbers and credit card numbers. Given how easy it is to strip characters out of a string, one wonders why people bother mandating a particular pattern.
- jwr 17y agoExactly. And note that if you overzealously validate, you'll get garbage data anyway. What do you think I enter as a phone number if I can't enter my number at all?
- jasonlotito 17y agoThe best approach is to fix it for the person behind the scenes. You can keep the original input (you should), but you should also reformat the phone number in an acceptable format for your uses. This does take a lot of work, however. It's not reasonable to ask someone to add their country code to their phone number. However, you do have the ability to add it yourself. And you should. It won't always be a human that needs the phone number.