Skip to content

Ahmetaksungur/akstelephoneinput

Repository files navigation

aksTelephoneInput.js

International Telephone Numbers

View the Demo on CodePen →

aksTelephoneInput

Getting Started

Compiled and production-ready code can be found in the dist directory.

1. Include aksTelephoneInput.min.js on your site.

Direct Download

You can download the files directly from GitHub.

<link type="text/css" rel="stylesheet" href="dist/aksTelephoneInput.min.css">
<script src="dist/aksTelephoneInput.min.js"></script>

CDN

<link type="text/css" rel="stylesheet" href="https://unpkg.com/[email protected]/dist/aksTelephoneInput.min.css">
<script src="https://unpkg.com/[email protected]/dist/aksTelephoneInput.min.js"></script>

<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/aksTelephoneInput.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/aksTelephoneInput.min.js"></script>

jQuery

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

NPM

npm i akstelephoneinput

Document aksTelephoneInput.js

<input class="aks-input" type="text" id="tel" name="aks-telephone-input" />
$("#tel").aksTelephoneInput({
  valueNumberCode: false,
  flagsUrl: "https://unpkg.com/[email protected]/flags/"
});

Sample.

Auto Country

$("#tel").aksTelephoneInput({
  valueNumberCode: false,
  autoCountry: true,
  geoCountries: function (callback) {
    $.get("https://ipwhois.app/json/", function (data) {
      callback(data.country_code);
    });
  },
  flagsUrl: "https://unpkg.com/[email protected]/flags/"
});

Sample.

Change Country

$("#tel").aksTelephoneInput({
  valueNumberCode: false,
  changeCountry: function () {
    console.log(this);
  },
  flagsUrl: "https://unpkg.com/[email protected]/flags/"
});

Sample.

Attributes

        allCountries: [],
        onlyCountries: [],
        primaryCountries: [],
        currentCountries: "",
        autoCountry: false,
        geoCountries: function (callback) {
          $.get("https://ipwhois.app/json/", function (data) {
            callback(data.country_code);
          });
        },
        changeCountry: function () {},
        placeholderNumber: true,
        valueNumberCode: false,
        searchBar: true

License

The code is available under the MIT License.