1

In my asp.net application, I have to use the validation for mobile number length based on the country name selected in the dropdown.

I have googled for the solution, but couldn't able to find exact one.

Can anybody share the usefull link or info to me?

Praveen VR
  • 1,554
  • 2
  • 16
  • 34

1 Answers1

1

Short answer:

You can't (unless you're limited to a very specific subset of countries).

Long answer:

Telephone systems are too varied and - in short - non-standardized to create one "catch all" solution.

While some countries, like the US, got fixed length numbers, others, e.g. Germany, got variable lenghts.

For example, the area code for landlines in Germany is always 5 digits long (4 digits if you're calling from another country). However, for mobile phones it's always 4 digits (3 digits calling from another country).

The actual (local) phone number then can be anything from 3 digits up to 7 or more.

My parents have a telephone they've got ages ago - 4 digits (9 digits total with area code). If I'd get a new contract today, I'd most likely end up with 6 or 7 digits (12+ digits total).

What you could do

Rather than checking for complete numbers, you could try to use a regular expression (see Shekhar's comment above) to verify a proper formatting (e.g. to include the country selection). While this isn't a perfect solution, it should help you avoiding confusing input users left by accident.

Mario
  • 35,726
  • 5
  • 62
  • 78