When filling in a form with real time validation and contextual help, how should one communicate the logic behind the telephone number validation?

For example, then contextual help would give hints such as:

  • Your contact number should contain 10 or 11 digits
  • The telephone number is either invalid or inappropriate

For the case of "The telephone number is either invalid or inappropriate" how would you tell - with a clear and transparent phrase - that the person needs to enter a valid number and what format to follow?

  • 8
    Just quick info: Telephone numbers around the world won't always have 10 or 11 digits. (My German cellphone has 12, for example, German land lines often have 9). Unless you are absolutely sure that every single one of your users will have a 10 or 11 digit number, I'd remove the constraints altogether. – MrLemon Jan 27 '15 at 12:45
  • 1
    Unrelated to the previous comment: Can you elaborate a bit on what you mean by "invalid" or "inappropriate"? – MrLemon Jan 27 '15 at 12:47
  • Will you allow + or spaces or ( or - in the number? or ext. – mmmmmm Jan 27 '15 at 15:07
  • 1
    Call 1-800-TXT-ONLY – DaveAlger Jan 27 '15 at 16:19

Unless you have an extremely homogenous audience, trying to validate a phone number is generally a bad idea. Phone numbers around the world are quite different, and even in the same area, there are a number of valid phone numbers. For example, in the Netherlands a typical mobile phone number may be given as: 0623456789. Here are the valid ways that I've seen people write this down without even considering character grouping:

  • 0623456789
  • +31623456789
  • +31(0)623456789
  • 0031623456789
  • 0031(0)623456789

All of the above are valid, and have differing allowed formats - and that's taking a single country, and only mobile phone numbers.

I've seen everything from 2 digit (in a small town in Namibia) to 12 digits (Germany) without even considering the variability in international dialling codes.

If you try to validate phone numbers, and your audience is even slightly heterogeneous, you're likely to cause more problems than you solve. I would advise against any phone number validation for 99% of cases.

| improve this answer | |
  • 2
    I agree. Also as a user I've came across sites where I have to try several times before the validation was "happy" with the format. – Alejandro Veltri Jan 27 '15 at 15:06
  • 1
    @rewobs Yes, and even then it often requires giving fake data. Not sure what the actual benefit of forcing users to give you fake data is. – Ville Niemi Jan 29 '15 at 10:14

There is a helper library for telephone numbers

Consider displaying a parse (the computers current interpretation) of the telephone number entered and letting the user provide "just enough" data to get their number interpreted right.

The computers best guess of valid and normalised telephone numbers can be powered by the Google libphonenumber library and data from browser locale, user IP (see examples on page). This library does have a very broad range of data acceptance and also knowledge of the legal telephone numbers.

While not "enforced validation" user can be quite sure whether number is credible or not. Library is probably robust enough for enforced validation, but that would allow unreachable numbers +1 555 555 5555 anyhow.

| improve this answer | |
  • I should point out that Google's libphonenumber library, while robust, is also heavy. If your use case is just validation, a heavy JS download like this may be overkill. I'd go back and question the value of validation first, as @JohnGB suggests. – Tim FitzGerald Jan 30 '15 at 1:43
  • @TimFitzGerald agree about importance. IMHO there are cases where it can be very important for user to be highly confident that their number will be interpreted correctly. Also note library does not need to be downloaded. Validations can be triggered by AJAX call with library server-side (with obvious notes on considerate network usage) – Jason A. Jan 30 '15 at 9:51

You can ask for the country (drop down) first, and having the correct format for that country, give an example of how you expect the phone number to be in (using hint text on the textbox could suffice).

I don't know how it is for other countries, but websites that generally target US users and ask for phone numbers seem to always validate the phone number to be in some specific format (e.g., 555-555-5555) if the input type is just a textbox. Sometimes three separate textboxes with hyphens (or parenthesis and hyphens) already provided are used, but these can be a minor hassle when entering using a keyboard and needing to correct a mistake and the backspace doesn't do what you think it will do.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.