Code Monkey home page Code Monkey logo

tel.js's Introduction

tel.js - An input[tel] directive for AngularJS.

A filter and a directive for input type 'tel' that formats and parses international phone numbers. Based on metadata from libphonenumber.

Demo: http://michaelkrog.github.io/tel.js/

#FILTER#

###Usage###

####In HTML Template Binding####

{{phonenumber_expression | telephone}}

####In Javascript####

$filter('telephone')(phonenumber, mode, defaultAreaCode, returnObject);

###Arguments###

Param Type Details
phonenumber string Phonenumber to format.
mode (optional) string 'e164'(international) or 'national' format. Default 'e164'.
defaultAreaCode (optional) string If specified phonenumbers from this area will be formatted even without an areacode.
returnObject (optional) boolean If true the result will be an object of the form `{number:,valid:<true

#DIRECTIVE#

###Usage### Load the tel.js module:

angular.module('<your module>', ['teljs']);

Use the directive as follows:

<input type="tel"
    ng-model=""
    [international=""]
    [default-area-code=""]>

###Arguments###

Param Type Details
ngModel string Assignable angular expression to data-bind to.
international (optional) string Wether number should be formatted as 'e164' or 'national' format. 'true' or 'false'. Default 'true'.
defaultAreaCode (optional) string If specified phonenumbers from this area will be formatted even without an areacode.

#Install#

You can install tel.js via bower like this:

bower install teljs --save

Alternatively you can download the full source as a ZIP file from Github.

#FILE FORMAT# The metadatalite.js file is taken directly from the libphonenumber repository. The format is defined by Google protobuf definitions and is therefore not very human readable. The following is a partial definition of the format - enough to build tel.js around the file.

It is two Objects

The whole file consists of 2 objects in the variables i18n.phonenumbers.metadata.countryCodeToRegionCodeMap and i18n.phonenumbers.metadata.countryToMetadata.

i18n.phonenumbers.metadata.countryCodeToRegionCodeMap holds a map of which countries use a given areacode.(fx. +45 is Denmark only, but +1 is a NANPA number and is used for USA, Canada and at least 20 other countries. The map refers to an array of countrycodes that uses a given area code having the main country as the first element in the array.

i18n.phonenumbers.metadata.countryToMetadata holds metadata for each country. Each metadata entry is retrieved by its countrycode(fx. 'DK'). The metadata entry is an array whici format is partly explained in the following table:

Field Note
0 unknown
1 generalDesc: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
2 fixedLine: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
3 mobile: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
4 tollfree: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
5 premiumrat: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
6 sharedCost: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
7 personalNumber: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
8 voip: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
9 ISO countrycode (fx. 'DK')
10 areacode (fx. 45 for DK, 46 for SE etc.)
11 internation prefix
12 national prefix
13 preferred extension prefix
14 unknown
15 national prefix for parsing
16 national prefix transform rule
17 preferred international prefix
18 same mobile and fixed line pattern (boolean)
19 national number formats. Array with entries of the following format: [unknown, pattarn, format, [leadingdigits...], nationalPrefixFormattingRule, unknown, unknown]
20 international number formats. Array with entries of the following format: [unknown, pattarn, format, [leadingdigits...]]
21 pager: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
22 main country for code
23 leading digits
24 no international dialing: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
25 uan: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]
26 leading zero possible
27 emergency
28 voicemail: [unknown, unknown, nationalNumberPattern, possibleNumberPattern]

tel.js's People

Contributors

michaelkrog avatar cadriel avatar avinashjain881 avatar samstiles avatar

Watchers

Josh Comer avatar James Cloos avatar  avatar Jeff Thompson avatar Matt Jones avatar John Benson avatar  avatar Simon Robinson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.