A JavaScript plugin for entering and validating international telephone numbers

Overview

International Telephone Input Build Status

A JavaScript 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.

If you like it, please consider making a donation, which you can do from the demo page.

Sponsored by

Use Twilio's API to build phone verification, SMS 2FA, appointment reminders, marketing notifications and so much more. We can't wait to see what you build.

Table of Contents

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 (Using a bundler e.g. Webpack)

  1. Install with npm: npm install intl-tel-input --save or yarn: yarn add intl-tel-input

  2. Import CSS: import 'intl-tel-input/build/css/intlTelInput.css';

  3. Override the path to flags.png in your CSS

.iti__flag {background-image: url("path/to/flags.png");}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .iti__flag {background-image: url("path/to/[email protected]");}
}
  1. Import JS and initialise plugin:
import intlTelInput from 'intl-tel-input';

const input = document.querySelector("#phone");
intlTelInput(input, {
    // any initialisation options go here
});
  1. Recommended: initialise the plugin with the utilsScript option to enable formatting/validation, and to allow you to extract full international numbers using getNumber.

Getting Started (Not using a bundler)

  1. Download the latest release, or better yet install it with npm

  2. Include the stylesheet

<link rel="stylesheet" href="path/to/intlTelInput.css">
  1. Override the path to flags.png in your CSS
.iti__flag {background-image: url("path/to/flags.png");}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .iti__flag {background-image: url("path/to/[email protected]");}
}
  1. Add the plugin script and initialise it on your input element
<input type="tel" id="phone">

<script src="path/to/intlTelInput.js"></script>
<script>
  var input = document.querySelector("#phone");
  window.intlTelInput(input, {
    // any initialisation options go here
  });
</script>
  1. 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 (lazy) 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. We 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).

Initialisation Options

When you initialise the plugin, the first argument is the input element, and the second is an object containing any initialisation options you want, which are detailed below. Note: any options that take country codes should be 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.

autoHideDialCode
Type: Boolean Default: true
If there is just a dial code in the input: remove it on blur or submit. 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.

customContainer
Type: String Default: ""
Additional classes to add to the parent div.

customPlaceholder
Type: Function Default: null
Change the placeholder generated by autoPlaceholder. Must return a string.

intlTelInput(input, {
  customPlaceholder: function(selectedCountryPlaceholder, selectedCountryData) {
    return "e.g. " + selectedCountryPlaceholder;
  },
});

dropdownContainer
Type: Node Default: null
Expects a node e.g. document.body. Instead of putting the country dropdown next to the input, append it to the specified node, 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.

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, and then calls the success callback with the relevant country code. Also note that when instantiating the plugin, if the Promise object is defined, one of those is returned under the promise instance property, so you can do something like iti.promise.then(callback) to know when initialisation requests like this have completed.

Here is an example using the ipinfo.io service:

intlTelInput(input, {
  initialCountry: "auto",
  geoIpLookup: function(success, failure) {
    $.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
      var countryCode = (resp && resp.country) ? resp.country : "us";
      success(countryCode);
    });
  },
});

Note that the callback must still be called in the event of an error, hence the use of always in this example.
Tip: store the result in a cookie to avoid repeat lookups!

hiddenInput
Type: String Default: ""
Add a hidden input with the given name. Alternatively, if your input name contains square brackets (e.g. name="phone_number[main]") then it will give the hidden input the same name, replacing the contents of the brackets with the given name (e.g. if you init the plugin with hiddenInput: "full", then in this case the hidden input would have name="phone_number[full]"). On submit, it will automatically populate the hidden input with the full international number (using getNumber). This is a quick way for people using non-Ajax forms to get the full international number, even when nationalMode is enabled. Avoid this option when using Ajax forms and instead just call getNumber to get the full international number to send in the request. Note: requires the input to be inside a form element, as this feature works by listening for the submit event on the closest form element. Also note that since this uses getNumber internally, firstly it requires the utilsScript option, and secondly it expects a valid number and so should only be used after validation.

initialCountry
Type: String Default: ""
Set the initial country selection by specifying its country code. You can also set it to "auto", which will lookup the user's country based on their IP address (requires the geoIpLookup option - see example). Note that the "auto" option will not update the country selection if the input already contains a number.

If you leave initialCountry blank, it will default to the first country in the list.

localizedCountries
Type: Object Default: {}
Allows to translate the countries by its given iso code e.g.:

{ 'de': 'Deutschland' }

nationalMode
Type: Boolean Default: true
Allow users to enter national numbers (and not have to think about international dial codes). Formatting, validation and placeholders still work. Then you can use getNumber to extract a full international number - see example. This option now defaults to true, and it is recommended that you leave it that way as it provides a better experience for the user.

onlyCountries
Type: Array Default: undefined
In the dropdown, display only the countries you specify - see example.

placeholderNumberType
Type: String Default: "MOBILE"
Specify one of the keys from the global enum intlTelInputUtils.numberType e.g. "FIXED_LINE" to set the number type to use for the placeholder.

preferredCountries
Type: Array Default: ["us", "gb"]
Specify the countries to appear at the top of the list.

preventInvalidNumbers [REMOVED]
Prevent the user from entering invalid characters. Unfortunately this had to be removed for the reasons listed here: #79 Limit Input Characters to Formatted String Length.

separateDialCode
Type: Boolean Default: false
Display the country dial code next to the selected flag so it's not part of the typed number. Note that this will disable nationalMode because technically we are dealing with international numbers, but with the dial code separated.

utilsScript
Type: String Default: "" Example: "build/js/utils.js"
Enable formatting/validation etc. by specifying the URL of the included utils.js script (or alternatively just point it to the file on cdnjs.com). The script is fetched only when the page has finished loading (on the window load event) to prevent blocking (the script is ~215KB). When instantiating the plugin, if the Promise object is defined, one of those is returned under the promise instance property, so you can do something like iti.promise.then(callback) to know when initialisation requests like this have finished. See Utilities Script for more information.

Public Methods

In these examples, iti refers to the plugin instance which gets returned when you initialise the plugin e.g. var iti = intlTelInput(input)

destroy
Remove the plugin from the input, and unbind any event listeners.

iti.destroy();

getExtension
Get the extension from the current number. Requires the utilsScript option.

var extension = iti.getExtension();

Returns a string e.g. if the input value was "(702) 555-5555 ext. 1234", this would return "1234"

getNumber
Get the current number in the given format (defaults to E.164 standard). The different formats are available in the enum intlTelInputUtils.numberFormat - which you can see here. Requires the utilsScript option. Note that even if nationalMode is enabled, this can still return a full international number. Also note that this method expects a valid number, and so should only be used after validation.

var number = iti.getNumber();
// or
var number = iti.getNumber(intlTelInputUtils.numberFormat.E164);

Returns a string e.g. "+17024181234"

getNumberType
Get the type (fixed-line/mobile/toll-free etc) of the current number. Requires the utilsScript option.

var numberType = iti.getNumberType();

Returns an integer, which you can match against the various options in the global enum intlTelInputUtils.numberType e.g.

if (numberType === intlTelInputUtils.numberType.MOBILE) {
    // is a mobile number
}

Note that in the US there's no way to differentiate between fixed-line and mobile numbers, so instead it will return FIXED_LINE_OR_MOBILE.

getSelectedCountryData
Get the country data for the currently selected flag.

var countryData = iti.getSelectedCountryData();

Returns something like this:

{
  name: "Afghanistan (‫افغانستان‬‎)",
  iso2: "af",
  dialCode: "93"
}

getValidationError
Get more information about a validation error. Requires the utilsScript option.

var error = iti.getValidationError();

Returns an integer, which you can match against the various options in the global enum intlTelInputUtils.validationError e.g.

if (error === intlTelInputUtils.validationError.TOO_SHORT) {
    // the number is too short
}

isValidNumber
Validate the current number - see example. Expects an internationally formatted number (unless nationalMode is enabled). If validation fails, you can use getValidationError to get more information. Requires the utilsScript option. Also see getNumberType if you want to make sure the user enters a certain type of number e.g. a mobile number.

var isValid = iti.isValidNumber();

Returns: true/false

setCountry
Change the country selection (e.g. when the user is entering their address).

iti.setCountry("gb");

setNumber
Insert a number, and update the selected flag accordingly. Note that if formatOnDisplay is enabled, this will attempt to format the number according to the nationalMode option.

iti.setNumber("+447733123456");

setPlaceholderNumberType
Change the placeholderNumberType option.

iti.setPlaceholderNumberType("FIXED_LINE");

Static Methods

getCountryData
Get all of the plugin's country data - either to re-use elsewhere e.g. to populate a country dropdown - see example, or to modify - see example. Note that any modifications must be done before initialising the plugin.

var countryData = window.intlTelInputGlobals.getCountryData();

Returns an array of country objects:

[{
  name: "Afghanistan (‫افغانستان‬‎)",
  iso2: "af",
  dialCode: "93"
}, ...]

getInstance
After initialising the plugin, you can always access the instance again using this method, by just passing in the relevant input element.

var input = document.querySelector('#phone');
var iti = window.intlTelInputGlobals.getInstance(input);
iti.isValidNumber(); // etc

loadUtils
An alternative to the utilsScript option, this method lets you manually load the utils.js script on demand, to enable formatting/validation etc. See Utilities Script for more information. This method should only be called once per page. If the Promise object is defined, one of those is returned so you can use loadUtils().then(callback) to know when it's finished.

window.intlTelInputGlobals.loadUtils("build/js/utils.js");

setCountryData [REMOVED]
Set the plugin's country data. This method was removed because it makes much more sense to just use getCountryData and then modify that (see example) instead of having to generate the whole thing yourself - the country data has become increasingly complicated and for each country we now have five properties: the name, iso2 country code, international dial code, priority (in case two countries have the same international dial code), and finally a list of area codes used in that country - see data.js for more info.

Events

You can listen for the following events on the input.

countrychange
This is triggered when the user selects a country from the dropdown.

input.addEventListener("countrychange", function() {
  // do something with iti.getSelectedCountryData()
});

See an example here: Country sync

open:countrydropdown
This is triggered when the user opens the dropdown.

close:countrydropdown
This is triggered when the user closes the dropdown.

Utilities Script

The utilities script (build/js/utils.js) is a custom build of Google's libphonenumber which enables the following features:

  • Formatting upon initialisation, as well as with getNumber and setNumber
  • Validation with isValidNumber, getNumberType and getValidationError methods
  • Placeholder set to an example number for the selected country - even specify the type of number (e.g. mobile) using the placeholderNumberType option
  • Extract the standardised (E.164) international number with getNumber even when using the nationalMode option

International number formatting/validation is hard (it varies by country/district, and we currently support ~230 countries). The only comprehensive solution I have found is libphonenumber, from which I have precompiled the relevant parts into a single JavaScript file and included in the build directory. Unfortunately even after minification it is still ~215KB, but if you use the utilsScript option then it will only fetch the script when the page has finished loading (to prevent blocking). If size is not a concern, then you can manually include the script yourself however you like, and as long as it has loaded before you initialise the plugin then it should work fine.

To recompile the utils script yourself (e.g. to update the version of libphonenumber it is built from), see the contributing guide.

Troubleshooting

Full width input
If you want your input to be full-width, you need to set the container to be the same i.e.

.iti { width: 100%; }

dropdownContainer: dropdown not closing on scroll
If you have a scrolling container other than window which is causing problems by not closing the dropdown on scroll, simply listen for the scroll event on that element, and trigger a scroll event on window, which in turn will close the dropdown e.g.

scrollingElement.addEventListener("scroll", function() {
  var e = document.createEvent('Event');
  e.initEvent("scroll", true, true);
  window.dispatchEvent(e);
});

Input margin
For the sake of alignment, the default CSS forces the input's vertical margin to 0px. If you want vertical margin, you should add it to the container (with class iti).

Displaying error messages
If your error handling code inserts an error message before the <input> it will break the layout. Instead you must insert it before the container (with class iti).

Dropdown position
The dropdown should automatically appear above/below the input depending on the available space. For this to work properly, you must only initialise the plugin after the <input> has been added to the DOM.

Placeholders
In order to get the automatic country-specific placeholders, simply omit the placeholder attribute on the <input>.

Bootstrap input groups
A couple of CSS fixes are required to get the plugin to play nice with Bootstrap input groups. You can see a Codepen here.
Note: there is currently a bug in Mobile Safari which causes a crash when you click the dropdown arrow (a CSS triangle) inside an input group. The simplest workaround is to remove the CSS triangle with this line:

.iti__arrow { border: none; }

Contributing

See the contributing guide for instructions on setting up the project and making changes, and also for how to update to a new version of libphonenumber, or how to update the flag images.

Attributions

Links


Testing powered by BrowserStack Open-Source Program

Comments
  • Disable and remove autoFormat feature

    Disable and remove autoFormat feature

    I have been back and forth about this a lot - I spent a lot of time implementing the autoFormat feature and fixing bugs, and I think it's a super cool feature, BUT I think it's time to disable and remove it for the following reasons:

    • First and foremost, we are hacking libphonenumber to get this to work, which is dangerous. It was not made for this purpose, they do not support our use case, and they have explicitly advised us against using it this way.
    • When the user types we have to call preventDefault so we can control what happens, but this means we lose a bunch of useful native events like change and input, which other devs may depend on.
    • Last time I checked, autoFormat didn't work in Android Cordova apps, or in IE Mobile (see Browser Compatibility section of readme). Who knows what other browsers/versions/platforms make it not work properly.
    • There is no way around this incredibly counter-intuitive UX issue: https://github.com/jackocnr/intl-tel-input/issues/322 where you cannot type the first character from the placeholder. This affects 49 countries including the USA - see https://github.com/jackocnr/intl-tel-input/issues/346#issuecomment-183771143.
    • Another minor issue: even if we find a fix for the above issue, it will lead to a new one: when a country placeholder starts with a formatting char (e.g. US starts with an open bracket), if you press that char to try and start the number, you will get a red flash as that is not an accepted key, but then it will still add the char because autoFormat does a lookahead and adds any upcoming formatting chars on each keypress, which leads to a confusing experience.
    • Then there's all the issues we have already come across, which suggests to me that there are so many more we don't yet know about. We get bug reports for the popular countries, but much less for the unpopular ones, which means most likely they are buggy and we just don't know about it.
    • Finally, restricting what the user can do in a regular <input> is considered bad practice by a lot of people (I have yet to find an example of Google or Facebook doing anything like this). As we have seen, this approach is very prone to bugs, and when there are bugs it can completely ruin the UX, or even render the whole input useless. It's a very dangerous approach.

    Notes

    • We should still keep a formatNumber function available, which should be used with setNumber etc.
    • This change would render the allowExtensions option useless, so we would remove that too.
    • This change would also close issues: https://github.com/jackocnr/intl-tel-input/issues/190, https://github.com/jackocnr/intl-tel-input/issues/262 and https://github.com/jackocnr/intl-tel-input/issues/322
    • Another perk is that this should significantly decrease the file size of the plugin.

    I'm open to discussion, but at this point I'm pretty convinced, and would welcome a pull request that implemented this change.

    opened by jackocnr 38
  • Padding: padding left issue for input

    Padding: padding left issue for input

    I am using input in bootstrap modal, but it's adding padding left the size of window. please help me on this. I have noticed issue in the below code

    var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth()
    

    if this.selectedFlag.offsetWidth equal to 0 it's excuting this._getHiddenSelectedFlagWidth()

    but this function should modify like below

     {
                    key: "_getHiddenSelectedFlagWidth",
                    value: function _getHiddenSelectedFlagWidth() {
                        // to get the right styling to apply, all we need is a shallow clone of the container,
                        // and then to inject a deep clone of the selectedFlag element
                        var containerClone = this.telInput.parentNode.cloneNode();
                        containerClone.style.visibility = "hidden";
                        // to get the right width for selected flag make container position absolute
                        containerClone.style.position = "absolute"; //fix for padding issue
                        document.body.appendChild(containerClone);
                        var selectedFlagClone = this.selectedFlag.cloneNode(true);
                        containerClone.appendChild(selectedFlagClone);
                        var width = selectedFlagClone.offsetWidth;
                        containerClone.parentNode.removeChild(containerClone);
                        return width;
                    }
                }
    

    intltelinput-padding

    opened by srikanthreddy919 30
  • Chrome 63 is ignoring autocomplete=

    Chrome 63 is ignoring autocomplete="off"

    Chrome 63 is ignoring autocomplete="off", and tries to suggest previous user entries.

    The only solution is to assign a random string to the attribute, for example:

    autocomplete="nope"

    Source: https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion

    I think that we'll need a fix to that :(

    enhancement needs-dev 
    opened by ibarral 26
  • Slowly try to move away from jQuery

    Slowly try to move away from jQuery

    I'm making notes on ways we can incrementally move away from jQuery here: https://github.com/jackocnr/intl-tel-input/wiki/Removing-jQuery-Dependency

    Feedback appreciated on that wiki page - I'm sure there's a lot of jQuery references in the code that I've missed, and also clever native alternatives!

    I will happily accept pull requests towards this goal (in the branch f-remove-jquery), on the following conditions:

    • Each pull request only replaces ONE jQuery feature to keep things clean and simple, and allow discussion
    • It doesn't add too much bloat to the code
    • They are robust solutions that are unlikely to require maintenance
    • The tests pass

    Note that in order to make this project feasible, we will only support the latest version of all major browsers, which will enable us to use all standardised native methods (and recommend polyfills for browsers that are not standards compliant).

    Thanks for your help!

    (Please see wiki page for actionables)

    needs-dev breaking-change 
    opened by jackocnr 26
  • TypeError: $(…).intlTelInput is not a function

    TypeError: $(…).intlTelInput is not a function

    I'm trying to use intlTelInput for a HTML registration page but I am getting the following error: Uncaught TypeError: $(...).intlTelInput is not a function

    Here is the registration view code:

    
    <html>
    <head>
    <!-- Page for customer registration and submit details to database to associate SSO with company etc -->
        <link rel="stylesheet" type="text/css" href="views/register.css">
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <link rel="stylesheet" href="../bower_components/intl-tel-input/build/css/intlTelInput.css">
        <script src="../bower_components/intl-tel-input/build/js/intlTelInput.js"></script>
        <script>
            $("#phoneNumber").intlTelInput();
    
            // get the country data from the plugin
            var countryData = $.fn.intlTelInput.getCountryData(),
                telInput = $("#phoneNumber"),
                addressDropdown = $("#country");
    
            // init plugin
            telInput.intlTelInput({
                utilsScript: "../bower_components/intl-tel-input/build/js/utils.js" // just for formatting/placeholders etc
            });
    
            // populate the country dropdown
            $.each(countryData, function(i, country) {
                addressDropdown.append($("<option></option>").attr("value", country.iso2).text(country.name));
            });
            // set it's initial value
            var initialCountry = telInput.intlTelInput("getSelectedCountryData").iso2;
            addressDropdown.val(initialCountry);
    
            // listen to the telephone input for changes
            telInput.on("countrychange", function(e, countryData) {
                addressDropdown.val(countryData.iso2);
            });
    
            // listen to the address dropdown for changes
            addressDropdown.change(function() {
                telInput.intlTelInput("setCountry", $(this).val());
            });
        </script>
    </head>
    
    <form name="page1" id="page1" role="form">
    
    <div id="createCasePage1" class="container-fluid">
    
    <div class="col-md-6 col-xs-12">
            <div class="form-group">
    	      <label for="phoneNumber">Phone Number:</label>
              <input type="tel" id="phoneNumber" name="phoneNumber" ng-model="createUserObj[0].phoneNumber" class="form-control"  required>
          </div>
        </div>
    
        <div class="col-md-6 col-xs-12">
          <div class="form-group">
            <label for="country">Country:</label>
            <!--<input type="text" id="country" name="country" ng-model="createUserObj[0].country" class="form-control" placeholder="Country" required maxlength="100" /> -->
                  <select id="country" name="country" ng-model="createUserObj[0].country" class="form-control" required></select>
          </div>
        </div>
    
    
        <!-- Check valid  inputs and patterns then submit to controller -->
        <button type="submit" id="register" class="btn btn-large" class="registerBtn" ng-click="page1.$valid && createUserFunc()">Register</button>
        <br>
        <br>
    </div>
    </form>
    </html>
    
    

    I think it's an issue with jQuery and Angular but I'm not really sure.

    opened by ryanandrews321 22
  • Firefox Android - incorrect caret position when typing number in a masked field

    Firefox Android - incorrect caret position when typing number in a masked field

    When you try the demo on an Android device within Firefox for Android (which is a noteable browser, because it allows you to use Adblock Plus on your Android device lol), as you try to type a phone number, when the masking adds characters into the field around your number, the cursor skips to the wrong position.

    ie. as you type 6045551234... it types in as (604) 432-1555. Because as you type 604, masking adds a - to make it 604-. But then every digit you type goes before the -, so... 6045-, 60455-, 604555-, 6041555-, (604)215-55, etc...

    Works fine on Android Chrome however.

    bug 
    opened by mpiasta-ca 22
  • Change grunt build to npm run build

    Change grunt build to npm run build

    It's a pain for a contributor that doesn't have grunt installed globally to run build task as ./node_modules/.bin/grunt build. This PR fixes it to just npm run build and allows to change build system in the future without updating docs.

    opened by tinovyatkin 21
  • default options runs fine, as soon as custom options entered, utility JS file isn't loaded

    default options runs fine, as soon as custom options entered, utility JS file isn't loaded

    All the files are copied and referenced correctly, the plugin works fine if just using the default init line:

    $("#phone").intlTelInput();

    But whenever I even start to put brackets inside it, to provide custom settings, it breaks and doesn't load at all display an error Uncaught TypeError: Cannot read property 'extend' of undefined. This will also happen when providing no custom settings but still including brackets like:

    $("#phone").intlTelInput({});

    question 
    opened by ghost 21
  • Method to get only phone number without country code?

    Method to get only phone number without country code?

    This plugin is great, but the only thing I find that is missing is being able to easily just grab the phone number without the country code (in my case I want to store the values separately).

    I know that the getSelectedCountryData method can give me the country code so I can use regex to find out the rest, but it would be a lot easier if the plugin exposed a method to do that.

    enhancement 
    opened by rderharo 20
  • intlTelInput is not a function

    intlTelInput is not a function

    Hello, I know this issue has been reported many times but none of the answers have been able to fix my problem.

    Steps to reproduce

    Same as the Github ones, both css and js imports (that is the right path): <link rel="stylesheet" href="./node_modules/intl-tel-input/src/css/intlTelInput.css"> <script src="./node_modules/intl-tel-input/src/js/utils.js"></script> My input is generated dynamically with a 'tel' type I then check the type and execute the following code: if (columnData.forminfo.fields[u].inputtype === "tel") { var input = $("#"+columnData.forminfo.fields[u].inputid); window.intlTelInput(input); } But I also tried this (with the utils import too): var input = document.querySelector("#"+columnData.forminfo.fields[u].inputid); var iti = intlTelInput(input, { utilsScript: "https://cdn.jsdelivr.net/npm/[email protected]/build/js/utils.js", }); }

    Expected behaviour

    I should have had my input created with the flag version.

    Actual behaviour

    I get an error: 'intlTelInput is not a function'.

    Initialisation options

    I put my code above.

    If I don't use the window. in the first code, I get a 'intlTelInput is not defined' if it can help.

    Thanks!

    opened by eltoredo 19
  • Uncaught TypeError: $(...).intlTelInput is not a function after upgraded to jquery 3.1.1

    Uncaught TypeError: $(...).intlTelInput is not a function after upgraded to jquery 3.1.1

    Uncaught TypeError: $(...).intlTelInput is not a function

    Issue is coming after jquery upgrade. For older version jquery jquery-1.11.3 it was working fine. For upgraded version jquery-3.1.1 it is not working

    Steps to reproduce

    I have included css and js

    at the end of page

    opened by anupamadhuri 18
  • Formatting values with multiple inputs

    Formatting values with multiple inputs

    Steps to reproduce

    1. Following the getting started without bundle
    2. Instanciate two input type "tel" with as values attribute a valid phone number. I used asset 7.0.0

    Here is a working codepen of this example: https://codepen.io/gabriel9130/pen/YzjWovr . It is working well in codepen, but for some reason, the formatting of the first input is not right in my local project with the same code but set up without bundle with asset 17.0.0

    Expected behaviour

    The values of the inputs should be formatted correctly depending of the country.

    Actual behaviour

    The first value of the input is not well formatted (the raw value with country code is displayed) but the second one is correct. All the rest is working fine.

    image

    The code used is the same as the codepen provided before.

    Initialisation options

    window.intlTelInput(cell, { initialCountry: "br",
    hiddenInput: "whatsapp", autoPlaceholder: 'aggressive', utilsScript: "https://cdn.jsdelivr.net/npm/[email protected]/build/js/utils.js", });

    Others

    I know it would be better to provide you a codepen to reproduce the problem, but as the codepen works, I wonder if there can be a hidden bug somewhere. If it is an error in my local project, I can assure you that I followed the step to setup the project without bundles multiple times, with different assets, and everything seems fine, I can't find the source of the problem. Thank you for the help and the project.

    opened by SrimanNarayanaSangha 0
  • flag are looking so blurry specially USA

    flag are looking so blurry specially USA

    Steps to reproduce

    Expected behaviour

    Tell us what should happen

    Actual behaviour

    Tell us what actually happens

    Initialisation options

    List any options you're using e.g. utilsScript or preferredCountries

    opened by surindercrebos 0
  • HiddenInput name not working

    HiddenInput name not working

    Steps to reproduce

    1. Try hiddeninput with array

    WHen using a name like this on the input txRepeater[0][contact] the hiddenInput not works, can someone help figured out how i can have the hidden input being generated correclty txRepeater[0][contact][full] without problems

    Expected behaviour

    Tell us what should happen

    Actual behaviour

    Tell us what actually happens

    Initialisation options

    List any options you're using e.g. utilsScript or preferredCountries

    opened by mrelliot69 0
  • auto generate multiple instances and get data

    auto generate multiple instances and get data

    I am generating 2nd phone number input field dynamically and there is no limit to the number of input fields tha user can generate. This library works great on 1 field thats loaded with the page but how to make it work with n number of inputs? It might be simple but I am relatively new to jquery and ajax. At the moment my ajax script is creating an array of all phone number inputs and posting it to api. How can I create an array of multiple fields using getNumber() function in ajax?

    opened by fs0711 0
  • Prepopulated phone number leading zeros may be truncated when separateDialCode = true

    Prepopulated phone number leading zeros may be truncated when separateDialCode = true

    Steps to reproduce

    1. Set up an input with a valid Australian phone number: Example value: 0412 345 678
    2. Initialize phone input with "au" for the initialCountry and separateDialCode = true.

    Expected behaviour

    The country dial code should show by the flag and all digits of the phone number should be preserved.

    Actual behaviour

    The country dial code is shown by the flag, but the leading zeros of the phone number are truncated.

    Initialisation options

    phoneInput = document.querySelector("#phone_number_australia_sdc");
    iso2 = $("#phone_number_australia_sdc").data("iso2");
    
    window.intlTelInput(phoneInput, {
      preferredCountries: [iso2],
      initialCountry: iso2,
      separateDialCode: true
    });
    

    Notes

    This behavior occurs for other countries where leading zeros occur, such as Malaysia.

    If the utlisScript is removed from the initialization, the issue goes away. However, I need the utilsScript for other things. Perhaps this is a utilsScript issue? I apologize if so, but just in case it is, I tipped $2 in advance just to smooth things out. :-)

    Here's a plunker showing the issue: https://plnkr.co/edit/ZdspLuDNQLvhyw2K After loading the plunker preview, you may have to click on "Refresh live preview" to resolve some css issues.

    opened by shuttlehawk 0
  • Regular Expression error when using the component

    Regular Expression error when using the component

    Hi, I just downloaded ver 17.0.19. I had a problem to run this component. The errors in the console: first Error: Uncaught SyntaxError: Invalid regular expression: /^[a-zA-ZÀ-ÿа-яА-Я ]$/: Range out of order in character class
    The error was in intelTelInput.js :763

    Second error in my js file: Uncaught TypeError: window.intlTelInput is not a function. The error was for this row in my js: window.intlTelInput(input, { autoPlaceholder:"polite", utilsScript:'./build/js/utils.js' });

    This is the solution for this bug: Add charset="utf-8" to the script tag:

    I found this here: https://stackoverflow.com/questions/70917406/uncaught-syntaxerror-invalid-regular-expression-intltelinput/72238029#72238029

    The intel-tel-input team should add it to the demo here: https://github.com/jackocnr/intl-tel-input#getting-started-not-using-a-bundler

    regards, David

    opened by DavidOs55 0
Releases(v17.0.19)
🌐 Text Input Component for validating and formatting international phone numbers.

React Native Intl Phone Field Try the Expo Snack ?? ??️ Demo It's a javascript-only (no native code) component that can run in iOS, Android, Expo & Re

Ivanka Todorova 24 Jul 8, 2022
A jQuery-free general purpose library for building credit card forms, validating inputs and formatting numbers.

A jQuery-free general purpose library for building credit card forms, validating inputs and formatting numbers.

Jesse Pollak 528 Dec 30, 2022
Picky is a jQuery plugin that provides simple client-side date validation when entering dates using select tags.

jquery.picky.js Picky is a jQuery plugin that provides simple client-side date validation when entering dates using select tags. Features Instead of g

Patrick Crowley 5 Apr 25, 2021
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A project aimed at consuming the Where is ISS? api to track the current position of International Space Station.

ISS Tracker This project aims to create a website which tracks the live position of the Internation Space Station using this API. Issues: Call the api

Microsoft Learn Student Chapter, TIET 4 Oct 21, 2022
Little Javascript / Typescript library for validating format of string like email, url, password...

String-Validators Little Javascript / Typescript library for validating format of string like email, url, password... Signaler un Bug · Proposer une F

J.Delauney 3 Oct 14, 2022
An API for producing and validating ActivityPub objects.

ActivityHelper A library that exports an API for producing and validating ActivityPub objects. In a federated system bound together by protocols, it's

Diana Thayer 6 May 2, 2022
Fully-typed utilities for defining, validating and building your document

zhead Typed utilities for defining, validating and building best-practice document <head>'s. Status: Pre-release Please report any issues ?? Made poss

Harlan Wilton 70 Dec 21, 2022
Statistics plugin for RemNote that will give you some helpful numbers, charts and heatmap for your knowledge base.

RemNote statistics plugin Features This plugin will give you the following statistics: Retention rate Number of cards due in future Type of buttons yo

Henrik 3 Sep 9, 2022
front.phone is a Javascript library that identifies, validates and formats phone numbers.

front.phone front.phone is a Javascript library that identifies, validates and formats phone numbers. Demo The main goal of this project is to create

VTEX 55 Oct 27, 2022
no-comma is a javascript library for dealing with inputted numbers that include commas

no-comma no-comma is a javascript library for dealing with inputted numbers that include commas. Nocomma will allow you to check if the number contain

Fatty 3 Jan 27, 2022
An easy-to-use library to make your life easier when working with random numbers or random choices in javascript.

vrandom An easy-to-use library to make your life easier when working with random numbers or random choices in javascript. Table of contents Installati

Valerio Cipolla 1 Aug 16, 2022
A small JavaScript library to generate YouTube-like ids from numbers.

Hashids is small JavaScript library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user: htt

Bazyli Brzóska 3.9k Dec 30, 2022
Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.

fast-natural-order-by Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode charac

Shelf 5 Nov 14, 2022
An unreliable and overall unusable sorting library for numbers with a global cache on the edge.

unsort An unreliable and overall unusable sorting library for numbers with a global cache on the edge. the algorithm This library implements a number

Jonas Wanner 6 May 19, 2022
As babies smash on the keyboard, images, letters and numbers appear on the screen

Baby Bam Bam As babies smash on the keyboard, images, letters and numbers appear on the screen. Try the many options and find the ones that are right

Boris Fritscher 3 Oct 24, 2022
A CodeMirror (v6) extension for adding relative line numbers to your code editor

Relative Line Numbers for CM6 Installation yarn add codemirror-line-numbers-relative Usage import { EditorView } from "@codemirror/view"; import { Edi

Joe Previte 5 Feb 7, 2022