Java phone number format API

You could write your own (for US phone # format):

  • Strip any non-numeric characters from the string
  • Check that the remaining string is ten characters long
  • Put parentheses around the first three characters and a dash between the sixth and seventh character.
  • Prepend "+1 " to the string


Update:

Google recently released libphonenumber for parsing, formatting, storing and validating international phone numbers.


You could try this Java phone number formatting library https://github.com/googlei18n/libphonenumber

It has data for hundreds of countries and formats.