ngPhone

Angular service/filter for phone number validation/display


Keywords
angular, phone, number, format, validation, service, filter, libephonenumber, phoneformat
License
MIT
Install
bower install ngPhone

Documentation

ng-phone

Angular service/filter for phone number validation/display.

Install

Type:

bower install ngPhone

Include the script:

<script src="bower_components/ng-phone/ng-phone.js"></script>

Add a depencency:

var myApp = angular.module('myApp', ['ngPhone']);

Use

As a service:

myApp.controller('myController', function ($scope, ngPhone) {
  $scope.phone = '+12125556666';

  // Format
  var formattedPhone = ngPhone.format($scope.phone, 'local', 'US');

  // Validate
  var isValid = ngPhone.isValidNumber($scope.phone, 'US');
});

See elad/libphonenumber for more format() examples.

As a filter:

<div>
  {{ phone | phone:'local' }}
  {{ phone | phone:'local':'US' }}
</div>

Behaves exactly like filter().

Update

To sync with the latest version of libphonenumber, type:

./build.sh