-2

the length of mobile number varies from country to country. Tired regular expresssion but (Ex:India allows 10 digits, which is not validating UAE which ranges from 7 to 9 digits)

VinodBokare
  • 41
  • 2
  • 6
  • 3
    Within one country, it may vary from provider to provider. - What is your question? – laune Jun 22 '15 at 14:55
  • laune thanks for your reply. My Question is i have users from different countries, from UI screen the will add mobile numbers, so how can i write mobile number validation logic for different users based on there country. I have tried with Regex. but as country differ i need to change my Regex. I was in search of Generic code – VinodBokare Jun 22 '15 at 15:06

2 Answers2

2

you can try using Google's phone number library. It contains the isValidNumberfunction which provides "full validation of a phone number for a region using length and prefix information". https://github.com/googlei18n/libphonenumber

Ita
  • 901
  • 6
  • 21
1

Add this dependency to your pom.xml

<!-- https://mvnrepository.com/artifact/com.googlecode.libphonenumber/libphonenumber -->
<dependency>
    <groupId>com.googlecode.libphonenumber</groupId>
    <artifactId>libphonenumber</artifactId>
    <version>8.4.3</version>
</dependency>
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
La Carbonell
  • 1,976
  • 5
  • 22
  • 52