# International Telephone Input [![Build Status](https://travis-ci.org/jackocnr/intl-tel-input.svg)](https://travis-ci.org/jackocnr/intl-tel-input)
A jQuery plugin for entering and validating international telephone numbers. It adds a flag dropdown to any input, detects the user's country, displays a relevant placeholder and provides formatting/validation methods.
<img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshot.png" width="424px" height="246px">
If you like it, please consider making a donation, which you can do from [the demo page](http://intl-tel-input.com).
## Table of Contents
- [Demo and Examples](#demo-and-examples)
- [Features](#features)
- [Browser Compatibility](#browser-compatibility)
- [Getting Started](#getting-started)
- [Recommended Usage](#recommended-usage)
- [Options](#options)
- [Public Methods](#public-methods)
- [Static Methods](#static-methods)
- [Events](#events)
- [Utilities Script](#utilities-script)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [Attributions](#attributions)
## Demo and Examples
You can view a live demo and some examples of how to use the various options here: http://intl-tel-input.com, or try it for yourself using the included demo.html.
## Features
* Automatically select the user's current country using an IP lookup
* Automatically set the input placeholder to an example number for the selected country
* Navigate the country dropdown by typing a country's name, or using up/down keys
* Handle phone number extensions
* The user types their national number and the plugin gives you the full standardized international number
* Full validation, including specific error types
* Retina flag icons
* Lots of initialisation options for customisation, as well as public methods for interaction
## Browser Compatibility
| Chrome | FF | Safari | IE | Chrome Android | Mobile Safari | IE Mob |
| :----: | :--: | :----: | :--: | :------------: | :-----------: | :----: |
| ✓ | ✓ | ✓ | 11 | ✓ | ✓ | ✓ |
Note: In v12.0.0 we dropped support for IE9 and IE10, because they are no longer supported by any version of Windows - see https://www.xfive.co/blog/stop-supporting-ie10-ie9-ie8/
## Getting Started
1. Download the [latest release](https://github.com/jackocnr/intl-tel-input/releases/latest), or better yet install it with [npm](https://www.npmjs.com/package/intl-tel-input)
2. Include the stylesheet
```html
<link rel="stylesheet" href="path/to/intlTelInput.css">
```
3. Override the path to flags.png in your CSS
```css
.iti-flag {background-image: url("path/to/flags.png");}
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2 / 1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) {
.iti-flag {background-image: url("path/to/flags@2x.png");}
}
```
4. Add the plugin script and initialise it on your input element
```html
<input type="tel" id="phone">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="path/to/intlTelInput.js"></script>
<script>
$("#phone").intlTelInput();
</script>
```
5. **Recommended:** initialise the plugin with the `utilsScript` option to enable formatting/validation, and to allow you to extract full international numbers using `getNumber`.
## Recommended Usage
We highly recommend you load the included utils.js using the `utilsScript` option. Then the plugin is built to always deal with numbers in the full international format (e.g. "+17024181234") and convert them accordingly - even when `nationalMode` or `separateDialCode` is enabled. I recommend you get, store, and set numbers exclusively in this format for simplicity - then you don't have to deal with handling the country code separately, as full international numbers include the country code information.
You can always get the full international number (including country code) using `getNumber`, then you only have to store that one string in your database (you don't have to store the country separately), and then the next time you initialise the plugin with that number it will automatically set the country and format it according to the options you specify (e.g. if you enable `nationalMode` it will automatically remove the international dial code for you).
## Options
Note: any options that take country codes should be [ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) codes
**allowDropdown**
Type: `Boolean` Default: `true`
Whether or not to allow the dropdown. If disabled, there is no dropdown arrow, and the selected flag is not clickable. Also we display the selected flag on the right instead because it is just a marker of state.
**~~autoFormat~~ [REMOVED]**
Automatically format the number as the user types. Unfortunately this had to be removed for the reasons listed here: [#346 Disable and remove autoFormat feature](https://github.com/jackocnr/intl-tel-input/issues/346).
**autoHideDialCode**
Type: `Boolean` Default: `true`
If there is just a dial code in the input: remove it on blur or submit, and re-add it on focus. This is to prevent just a dial code getting submitted with the form. Requires `nationalMode` to be set to `false`.
**autoPlaceholder**
Type: `String` Default: `"polite"`
Set the input's placeholder to an example number for the selected country, and update it if the country changes. You can specify the number type using the `placeholderNumberType` option. By default it is set to `"polite"`, which means it will only set the placeholder if the input doesn't already have one. You can also set it to `"aggressive"`, which will replace any existing placeholder, or `"off"`. Requires the `utilsScript` option.
**customPlaceholder**
Type: `Function` Default: `null`
Change the placeholder generated by autoPlaceholder. Must return a string.
```js
customPlaceholder: function(selectedCountryPlaceholder, selectedCountryData) {
return "e.g. " + selectedCountryPlaceholder;
}
```
**dropdownContainer**
Type: `String` Default: `""`
Expects a jQuery selector e.g. `"body"`. Instead of putting the country dropdown next to the input, append it to the element specified, and it will then be positioned absolutely next to the input using JavaScript. This is useful when the input is inside a container with `overflow: hidden`. Note that the absolute positioning can be broken by scrolling, so it will automatically close on the `window` scroll event. If you have a different scrolling element that is causing problems, simply listen for the scroll event on that element, and trigger `$(window).scroll()` e.g.
```js
$("#scrollingElement").scroll(function() {
$(window).scroll();
});
```
**excludeCountries**
Type: `Array` Default: `undefined`
In the dropdown, display all countries except the ones you specify here.
**formatOnDisplay**
Type: `Boolean` Default: `true`
Format the input value (according to the `nationalMode` option) during initialisation, and on `setNumber`. Requires the `utilsScript` option.
**geoIpLookup**
Type: `Function` Default: `null`
When setting `initialCountry` to `"auto"`, you must use this option to specify a custom function that looks up the user's location. Also note that when instantiating the plugin, we now return a [deferred object](https://api.jquery.com/category/deferred-object/), so you can use `.done(callback)` to know when initialisation requests like this have completed.
Here is an example using the [ipinfo.io](https://ipinfo.io/) service:
```js
geoIpLookup: function(callback) {
$.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
callback(countryCode);
});
}
```
_Note that the callback mus
没有合适的资源?快使用搜索试试~ 我知道了~
JS加载世界各国手机区号、图标(可适用手机端)
共109个文件
js:67个
html:14个
css:6个
需积分: 43 18 下载量 83 浏览量
2018-07-13
10:52:09
上传
评论
收藏 537KB ZIP 举报
温馨提示
加载世界各国手机区号插件,包含图标,可根据IP加载当前国家的手机区号图标
资源推荐
资源详情
资源评论
收起资源包目录
JS加载世界各国手机区号、图标(可适用手机端) (109个子文件)
intlTelInput.css 27KB
intlTelInput.min.css 21KB
prism.css 2KB
demo.css 1KB
countrySync.css 116B
isValidNumber.css 106B
template.html.ejs 2KB
wrapper.js.ejs 584B
.gitignore 216B
country-sync.html 4KB
spec.html 3KB
is-valid-number.html 3KB
only-countries-europe.html 2KB
hidden-input.html 2KB
national-mode.html 2KB
default-country-ip.html 2KB
modify-country-data.html 2KB
demo.html 1KB
countrySync.html 376B
isValidNumber.html 136B
hiddenInput.html 100B
nationalMode.html 76B
simpleInput.html 29B
utils.js 222KB
intlTelInput.js 69KB
intlTelInput.js 49KB
intlTelInput.min.js 23KB
data.js 15KB
prism.js 7KB
utils.js 6KB
replace.js 6KB
template.js 5KB
dropdownShortcuts.js 4KB
initialValues.js 4KB
usingInput.js 3KB
separateDialCode.js 3KB
helpers.js 3KB
autoPlaceholder.js 3KB
autoHideDialCode.js 3KB
loadUtils.js 3KB
multipleInstances.js 2KB
nationalMode.js 2KB
usingDropdown.js 2KB
onlyCountries.js 2KB
isValidNumber.js 2KB
allowDropdown.js 2KB
dropdownContainer.js 2KB
destroy.js 2KB
getNumber.js 2KB
formatOnDisplay.js 2KB
setNumber.js 2KB
initialCountry.js 1KB
countrychangeEvent.js 1KB
geoIpLookup.js 1KB
excludeCountries.js 1KB
preferredCountries.js 1KB
responsive_images.js 1KB
utilsScript.js 1KB
closecountrydropdownEvent.js 1KB
getExtension.js 998B
getValidationError.js 994B
getNumberType.js 929B
sprite.js 926B
Gruntfile.js 914B
countrySync.js 892B
getSelectedCountryData.js 852B
placeholderNumberType.js 790B
customPlaceholder.js 762B
setPlaceholderNumberType.js 746B
isValidNumber.js 643B
uglify.js 615B
setCountry.js 586B
jasmine.js 580B
defaults.js 548B
nationalMode.js 487B
onlyCountriesEurope.js 415B
getCountryData.js 386B
sass.js 386B
defaultCountryIp.js 363B
retinafy.js 323B
watch.js 311B
jshint.js 287B
modifyCountryData.js 271B
imagemin.js 270B
bump.js 255B
exec.js 232B
cssmin.js 168B
hiddenInput.js 141B
shell.js 103B
index.js 103B
package-lock.json 209KB
package.json 1KB
intl-tel-input.jquery.json 650B
composer.json 579B
bower.json 164B
LICENSE 1KB
README.md 23KB
CHANGELOG.md 10KB
ISSUE_TEMPLATE.md 980B
CONTRIBUTING.md 932B
共 109 条
- 1
- 2
资源评论
P_Alex
- 粉丝: 6
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Android的学生信息管理2.rar
- 3e9ef566-ba13-47b0-a252-77aa9e4b040f8412130.apk
- 毕业设计基于SSM的房屋租赁系统源【源码+lw+部署+讲解】
- 基于Android男装出口管理系统的app.rar
- 工资表生成工资条Excel模版
- 位运算、状态压缩、枚举子集汇总.html
- C++毕业设计快递分拣机器人系统源码+论文文件+资料.zip
- 锐龙处理器 体质分析工具,体质越好越稳定,越容易超频 tool1007/Win V/F
- IOS Swift3 四种单例模式详解及实例《PPT文档》
- Swin-Unet网络预训练模型,swin-tiny-patch-window7-224.pth
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功