Currently on my website users are required to input their phone number in a very specific format (555-555-5555). If you forget the dashes it breaks. Does anyone have a good suggestions for how to be more flexible with allowing users to input in any way they choose, but still allowing the system to validate if it is a real phone number. How are phone extensions handled?
|
|
Ideally you'd let them type in the phone number in any format and you'd have client and server side logic that could parse it out. Barring that--if you're just looking for a quick fix--look at using field masking. If you're using jQuery, this is a decent one: |
|||
|
|
|
I'd steer away from using anything propriatary and instead refer to something standardised, like E.123. Because it's a recognised international standard, I would expect to find code examples - or even complete libraries - that you can plug into your validation process. |
|||
|
|
|
The best approach for user experience is to let the user type in the phone number using the format they are most comfortable with. Don't break it into separate fields, don't force a mask, let it be typed freeform. Then, after the user has finished entering the field (by leaving the field for submitting the data), format the number into a standard format for your purposes. Since you are talking about a Web site, you can do the format on the blur event using the Google libphonenumber http://code.google.com/p/libphonenumber/ project. This tool handles international phone numbers and a wide variety of formats. Here is an example in JavaScript: http://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers/demo.html The reason this approach is better for the user experience is that it allows the user's mental model to remain unchanged and allows them to say, "Don't Make Me Think." Masking and separate fields force a mental model of phone numbers onto users and requires more thinking. |
|||||||
|
|
You should just use a plain old text box and use your back-end code to parse it if you really need to. I personally don't see a need to require any specific format whatsoever. If a user wants to be able to just enter the 10 digits of their phone number really quickly, then let them. You also need to remember that there isn't just one format in the world to deal with, and you may also need to deal with weird cases like extensions. |
|||||
|
|
Edit: 18 November 2010 Found one more good article today http://formulate.com.au/research/mobile-phone-numbers/ Keep in mind the ability of iPhone also http://hjacob.com/blog/2009/07/making-a-phone-number-clickable-for-iphone-users/ |
|||
|
|
|
Let users enter numbers as well as '-' and spaces, so you can enter the number the way they prefer. As long they enter sufficient numbers, it can be a valid phone number. You can use client-side validation to count the numbers and show a message if there are too few. You will never be able to verify if the phone number is really activated, so typing errors are unavoidable. The server can parse the other characters out and just store the numbers in the database (and parse it back to your preferred formatting for display purposes). |
|||
|
|
|
The most friendly format is a format that will accept everything and doesn't do any validation. We are talking about phone numbers here, not credit card information. How many people are mistyping their phone number? Unless this is a site for the International Dyslexic Association, probably no one. The only thing you can validate is a format. You still don't know if the number is correct. |
|||||||||
|
|
The simplest UI approach is to break the number format into three limited text boxes. Alternatively use a RegEx to parse the entered phone number into what ever format the system needs to accept a phone number. i.e. accepting - 0-9 +()- |
|||||||||||||||||
|
|
Another option is what I did on one of my sites:
Example: User enters this into the field: 055 (0)555-555 55555 I display radio boxes underneath the form to ask for confirmation: How do you call your number from another country? That way I can confirm the user's phone number and know exactly how to deal with it, since I need to know the user's country code... |
|||
|
|