npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-valid-phone

v1.0.3

Published

Angularjs directive which use google's libphonenumber library for international phone number validations.

Downloads

8

Readme

Ng Valid Phone

npm version Bower dependency Status license

Angularjs directive which use google's libphonenumber library for international phone number validations.

Installation

npm install ng-valid-phone
bower install ng-valid-phone

Features

  • International number validation.
  • National number validation.
  • Number masking and filtering
  • Example numbers as placeholders.
  • Defining countryCode ability.
  • Simple and fast integration.

Usage

  • Add 'libphonenumber.js' and 'ng-valid-phone.js' to your source.
<script src="bower_components/google-libphonenumber/dist/libphonenumber.js"></script>
<script src="bower_components/ng-valid-phone/dist/ng-valid-phone.js"></script>

Basic Setup

  • Add ng-valid-phone directive to your html element.
  • With basic setup, validation will work for all international numbers.
  • Eg; 86 431 2344 1234 (CH) - 1 201 555-1234 (US)
<input type="text" ng-model="test" ng-valid-phone />

Country Code Setup

  • You can use country code (2 letter regional code) option to get only national number with its pattern.
  • countryCode should be initialize as a variable. In this way you can create a select box for your country list.
  • Or simply you can use ng-init to initialize countryCode in temaplate like in this example.
<input type="text" ng-model="test" data-country-code="countryCode" ng-init="countryCode='US'" ng-valid-phone />

Placeholder Setup

  • If you define a country-code param, you can use place-holder option too. It will show an example national number for the defined country.
<input type="text" ng-model="test" data-place-holder="1" data-country-code="countryCode" ng-init="countryCode='US'" ng-valid-phone />

Example

You can set error/success messages by using angular's basic validation checks.

<form name="myForm">
  <input type="text" ng-model="test" name="test" data-place-holder="1" data-country-code="countryCode" ng-init="countryCode='US'" ng-valid-phone />
  <span ng-show="!myForm.test.$valid">Please enter a valid number.</span>
  <span ng-show="myForm.test.$valid">Your phone number is valid.</span>        
</form>

Notes

  • If you define a countryCode, validation will be done only for that country.
countryCode:US,  Valid numbers: 1201 555 1234 - 201 555 1234
  • if client uses country code at the beginning it will be removed after validation automatically.
countryCode:US,  Number: 1201 555 1234 or 0201 555 1234 will be changed to 201 555 1234 after the last digit is entered.
  • If you dont specify a country code, validation will be done for all international numbers.
Eg; Valid numbers: 86 431 2344 1234 (CH) - 90 531 232 12 34 (TR) - 1 201 555-1234 (US)

License

MIT license.