Giter VIP home page Giter VIP logo

angular-phonenumber-formatter's Introduction

This library formats American national numbers and international numbers using Angular, Googles i18n Phone Number Formatter.

See Demo

NOTE: This was made for a specific project, so is not very configurable.

Requirements

  • AngularJS
  • Lodash

Assumptions

  • National numbers are American numbers. They will be decorated as (###) ###-####.
  • X's are not stripped from national numbers as they could be the precursor for extensions. Other letters are.
  • X's are stripped from international extensions (a company decision)
  • If a national number has more than 10 digits, it will format the first 10 digits and append the rest, seperated by a space.
    • Eg: 1234567890x123 becomes (123) 456-7890 x123
  • International numbers will begin with a "+" to differentiate them from national numbers

Usage

Setup

Add the module as a dependency

angular.module( "app", [
   "phoneNumberFormatter"
] );

Input

Add "phone-number" as an attribute and the value as ng-model

<input type="text" ng-model="myPhoneNumber" phone-number></input>

Element

Use "phone-number" as an attribute or element. Add the value as ng-model. If you're using it as an attribute, be aware that it creates an isolate scope, so you cannot use another attribute that creates an isolate scope on the same element

<phone-number ng-model="myPhoneNumber"></phone-number>

or

<p phone-number ng-model="myPhoneNumber"></p>

Filter

<p>{{myPhoneNumber|phoneNumber}}</p>

or

$scope.myPhoneNumber = $filter('phoneNumber')($scope.myPhoneNumber);

Factory (PhoneNumberFormatter)

Inject PhoneNumberFormatter as a dependency.

var myNum = 1234567890,
    numberFormatter = new PhoneNumberFormatter();

var formattedNumber = numberFormatter.getFormattedNumber(myNum); //(123) 456-7890
var isInternational = numberFormatter.isInternational(myNum); //false
var unformattedNumber = numberFormatter.trim(myNum); //1234567890

Demo

  1. Download app
  2. cd into "demo"
  3. Run "npm install"
  4. Run "bower install"
  5. Run "grunt serve"

angular-phonenumber-formatter's People

Contributors

lposen avatar

Watchers

James Cloos avatar  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.