title: Java phone number format API
body: <p>I have a database with millions of phone numbers with free-for-all formatting. Ie, the UI does not enforce any constraints and the users are typing in whatever they want.</p>
  
  <p>What I'm looking for is a Java API that can make a best-effort to convert these into a consistent format. Ideally, the API would take the free text value and a country code and produce a valid international phone number or throw an exception.</p>
  
  <p>For example, a phone number in the system might look like any of the following:</p>
  
  <pre><code>(555) 478-1123
  555-478-1123    
  555.478.1123
  5554781123
  </code></pre>
  
  <p>Given the country of US, the API would produce the value "+1 (555) 478-1123" for all these. The exact format does not matter, as long as it's consistent.</p>
  
  <p>There are also numbers in the system without area codes, such as "478-1123". In that case, I would expect a NoAreaCodeException, or something similar.</p>
  
  <p>There could also be data such as "abc", which should also throw exceptions.</p>
  
  <p>Of course, there are countless variations of the examples I have posted, as well as the enormous complication of international phone numbers, which have quite complicated validation rules. This is why I would not consider rolling my own.</p>
  
  <p>Has anyone seen such an API?</p>