5 ms·
I wish author was a little more constructive here. What phone number pattern would he recommend we use?
by awolf 17y ago
I wish author was a little more constructive here. What phone number pattern would he recommend we use?
- snitko 17y agoWhy use any pattern? Let me enter the phone number in a way I got used to it and deal with it.
- raganwald 17y agoThere's a cost/benefit analysis to be done. People do make mistakes, and checking their submission against common patterns will save you lost sales. As suggested in a comment on a rant I wrote a few years ago, one strategy is to 'validate' against something reasonable, but instead of rejecting anything that fails, ask the user to confirm that they really do want something unexpected. I'm not sure that 'reasonable' would be for an international phone number, but whatever you pick based on the country they choose, let them override your validation.
- jacoblyles 17y agoWell, I suppose you could just validate numbers from the most common countries you see and hope the rest don't make mistakes. Call it the Amdahl's law of internationalization.
- barrkel 17y agoConfirmation is OK, but taking a hard line is a no-no. I've had endless problems trying to jam my Irish mobile phone number (for a long time, my primary phone) into UK phone number fields.
- sigzero 17y agoUmmm...no. Do you not see the problem with that reasoning?
- Vivtek 17y agoWhat, the whole "being able to place an order even if you're not American" thing?
- whyenot 17y agoI'm not snitko, but I don't see the problem. Could you please explain your reasoning?
- Semiapies 17y agoTo be blunt, inputs you don't validate are inputs that will be entered wrong a significant portion of the time. Other concerns may override this for many fields, but unusable phone numbers are generally considered a problem.
- whyenot 17y agoYes, but if you over-validate you also risk losing sales. What to do doesn't seem obvious at all, at least to me. You'd want to do some kind of cost-benefit analysis Also, wouldn't a phone number in effect be validated for most online credit card purchases? I thought credit card processor often match the phone number you provide to the phone number on record for your account to prevent fraud. Skip the javascript validation, and let the cc processor validate the phone number. ...but I have no idea what I'm talking about, please correct me if I'm wrong.
- Semiapies 17y agoIt's not universally true, no. If you under-validate, you risk sales you can't complete. Mind, that's less dire when you have email addresses - but we know the problems with trying to validate those on forms.
- mattm 17y agoIf you force people to enter a phone number in a format they don't have, you will just end up with a bunch of 555-555-5555 numbers. Either way, you are going to get incorrect information. It's much better to realise that your information will not always be 100% accurate no matter what you do.
- bobbyi 17y agoBecause that's scary for users who have anxiety worrying they didn't input things correctly. If you tell them the phone number format and have a state dropdown, people rest easy knowing you will get their contact info correct.
- DeusExMachina 17y agoProbably 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.
- skybrian 17y agoFor phone numbers, this library might help: http://code.google.com/p/libphonenumber/ http://code.google.com/p/libphonenumber/
- detst 17y agoVery nice. Anyone have links for other languages? Python and ruby in particular. My take is that we need to validate (people screw up and often), ask them to verify when we can't validate and proceed after verification.
- maw 17y agoGood question. Unless there's some table valid phone number patterns corresponding to various regions, the best you can do might be to check for dashes, digits, dots, and parenthesis. Maybe also check that it doesn't exceed some arbitrary but generous length, too. (Ugly, I know.)
- ismarc 17y agoE.164 format. Every valid number in the world can be represented. The downside is that most people don't even know that this exists, so when doing an international based system, you have a filter based on the country they user is based in and automatically apply any codes needed. Just strip everything out of the field that isn't a number and prepend the country code if the region doesn't normally include it. That means that 210-555-1212 would become 12105551212 for a U.S. number and 21-555-1212 would become 55215551212 for a Brazil number.
- timthorn 17y agoThe transform isn't that simple. For example, UK numbers start with a 0 to indicate STD (long distance) - but that 0 must be stripped for calls from another country. Ie, 01234 567890 is dialed from abroad as +44 1234 567890.
- ismarc 17y agoThis gets into dial semantics vs. number format, which then becomes an element of user behavior. I don't know how user behavior is in a large number of other countries, but the U.S. I know typical reaction to "enter your full phone number" is area code + number, not 1 + area code + number.
- timthorn 17y agoIndeed. In the UK, the zero is always regarded as part of the area code.
- acg 17y agoAdditionally these rules can and do change. For example I know that the national numbering plan in the Czech Republic changed around 2002 for instance so a leading 0 for national calls was removed. Getting all websites in the world to understand changing numbering plans would be quite a feat, and for most sites not worth the effort. http://www.itu.int/itudoc/itu-t/number/c/cze/76045.html http://www.itu.int/itudoc/itu-t/number/c/cze/76045.html
- chronomex 17y agohttp://wtng.info/ http://wtng.info/ would be a good place to start. It's a lot of work to do right. You have to support full international numbers as short as 7 digits (Tokelau has +690 XXXX) and as long as 15 digits (in Germany the telco basically gives subscribers a subnet-like functionality, as extra dialled digits are passed along during call origination). Ideally you'd be able to parse it into a punctuation format based on local practice, but just about everyone punts on that.