Phone number format and validation library [closed]

谁说胖子不能爱 提交于 2019-11-27 12:52:40

Such an API in any language: Number::Phone (example submodule: Number::Phone::US).

Data: the ITU's National Numbering Plans index.

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

At http://www.geonames.org/ they have a database you can download, theres regEx rules for phone numbers included in the country info dataset.

http://download.geonames.org/export/dump/

Look for the 'countryInfo.txt' file.

I suggest you build your own validator based upon that.

Like it was said in the answers to the other question, no one's seen any for Java, and like you said, it would be nearly impossible due to the difference of phone number formats across the world.

And if you know the different formats for the regions that you're targeting, then it's usually pretty easy to implement it in regular expressions.

You can check out Parsify Format here - https://www.mashape.com/parsify/format#endpoint-Phone-Number

It will return your number in several formats e.g.

{ "e164": "+1234567890", "national": "234567890", "international": "+1 234567890", "valid": false, "type": "UNKNOWN" }

You can get a more extensive response if it's a real number

Phone Input field :

<input class="left" id="field" name="field" />

jquery Script:

jQuery.validator.addMethod("phoneUS", function(phone_number, element) { phone_number = phone_number.replace(/\s+/g, ""); return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(1-?)?(([2-9]\d{2})|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/); }, "Please specify a valid phone number");

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!