GithubHelp home page GithubHelp logo

hhy5277 / phone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aftership/phone

0.0 1.0 0.0 363 KB

With a given country and phone number, validate and format the MOBILE phone number to E.164 standard

License: MIT License

JavaScript 98.86% HTML 1.14%

phone's Introduction

Phone · Build Status codecov PRs Welcome

What is phone?

phone is used to normalize the mobile phone number into a E.164 format.

The common problem is user normally input the phone number in this way:

`(817) 569-8900` or
`817569-8900` or
`1(817) 569-8900` or
`+1(817) 569-8900` or ...

What we want is always:

+18175698900

Install

npm install phone

Usage

import phone from 'phone';
phone('+852 6569-8900'); // return ['+85265698900', 'HKG']
phone('(817) 569-8900'); // return ['+18175698900, 'USA']
phone('(817) 569-8900', ''); // return ['+18175698900, 'USA']
phone('(817) 569-8900', 'USA'); // return ['+18175698900', 'USA']
phone('(817) 569-8900', 'HKG'); // return []
phone('+1(817) 569-8900', 'HKG'); // return [], as it is not a valid HKG mobile phone number
phone('+1(817) 569-8900', ''); // return ['+18175698900', 'USA']
phone('(817) 569-8900', ''); // return ['+18175698900', 'USA']
phone('6123-6123', ''); // return [], as default country is USA
phone('6123-6123', 'HKG'); // return ['+85261236123', 'HKG']

Test

npm test

Old browsers & browser support

We currently transpile script to base on target env which that browser global usage '>1%' and "node: 6.10".

You can check on the browserlist You also need polyfill for some old browser more details please read the README inside the example folder

FAQ

  1. Does phone do any phone validation?

    Yes: If you provide the 2nd parameter (country), and the phone number do not start with + sign.

    phone will validate phone_number_lengths and mobile_begin_with

  2. Why some of the number is valid, but return null? This npm is used to validate a mobile phone number for sending the SMS. So, we try to match all possible rule, such as area code, number prefix, etc. to test if it is a mobile phone number. However, some countries, like USA, we can only check if it is a valid AREA CODE, there is no mobile phone prefix.

    For UK, we know that mobile phone number is always start with 7, in this case, this npm will be more helpful.

  3. Why do you make this?

    Because we need to normalize the phone number for SMS notification for mobile phone only.

We don't validate if the number is mobile or not.

Help

We try to google for many results, but none of package can fit our need. If you know that our rule is wrong, or can add more validation to make this npm more accurate. Please open an issue and let us know.

License

MIT

phone's People

Contributors

adam0x01 avatar adityabansod avatar aftership-admin avatar clark0x avatar dsasidhar avatar ebaynaud avatar gedex avatar hans-lizihan avatar herkyl avatar hiukwok avatar hpogosyan avatar ifroz avatar isaiahjturner avatar jonlil avatar julien-leroy avatar kode4food avatar luongvm avatar lykmapipo avatar marcioklein avatar maximization avatar neekey avatar rbudiharso avatar richardhills avatar secretbase avatar serega3000 avatar sudothinker avatar teddychan avatar torayeff avatar unek avatar wilzi avatar

Watchers

 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.