Google’s library for dealing with phone numbers
By admin on Jan 5, 2011 in Java, open source
libphonenumber is a Google’s common Java library for parsing, formatting, storing and validating international phone numbers. Optimized for running on smartphones. A direct port to Javascript is also available.
Let’s say you have a string representing a phone number from Switzerland, this is how you parse/normalize it into a PhoneNumber object:
String swissNumberStr = "044 668 18 00"
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
PhoneNumber swissNumberProto = phoneUtil.parse(swissNumberStr, "CH");
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}
At this point, swissNumberProto contains:
{
country_code: 41
national_number: 446681800
}
Sorry, comments for this entry are closed at this time.