GithubHelp home page GithubHelp logo

maxifjaved / phone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aftership/phone

1.0 1.0 0.0 604 KB

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

License: MIT License

JavaScript 94.36% HTML 0.99% TypeScript 4.65%

phone's Introduction

Phone · Build Status codecov PRs Welcome

What is phone?

phone is used to normalize mobile phone numbers into E.164 format.

A common problem is that users normally input phone numbers in this way:

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

We always want:

+18175698900

Install

npm install phone

Usage

const phone  = require('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

Build

yarn build

Old browsers & browser support

We currently transpile script to work on target environments for which the browser's global usage is >1%, and Node.js 6.10+.

You can check browser usage statistics on the browserlist.

You may need polyfills for some older browsers; for more details, please read the example/README file.

FAQ

  1. Does phone do any logical validation?

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

    phone will validate phone_number_lengths and mobile_begin_with

  2. Why is phone returning null for a valid phone number?

    This package is used to validate a mobile phone number for sending the SMS.

    Therefore, we try to match all possible rules for specifically checking whether a number is mobile, such as area code, number prefix, etc.

    However, some countries, like the USA, don't have mobile identifiers, so we can only check if the input has a valid area code.

    For example, we know that UK mobile phone numbers always start with 7. In this case, phone can verify that the number is actually mobile.

Help

We've tried to make sure that this package works for as many cases as possible, if you notice that we have an incorrect rule for a country or other case, please open an issue to let us know.

For creating new pull requests regarding add or modify phone number formats, please include the reference information such as PDFs, websites, etc. Thank you very much.

License

This project is licensed under the MIT license.

phone's People

Contributors

adam0x01 avatar adityabansod avatar aftership-admin avatar bossa573 avatar dsasidhar avatar gongbaodd avatar hans-lizihan avatar herkyl avatar hiukwok avatar ifroz avatar julien-leroy avatar kode4food avatar luongvm avatar lykmapipo avatar marcioklein avatar maximization avatar neekey avatar rbudiharso avatar richardhills avatar rssnorbertkeri avatar secretbase avatar serega3000 avatar soutoukakka avatar sudothinker avatar tallguys avatar teddychan avatar torayeff avatar unek avatar waksana avatar wilzi avatar

Stargazers

 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.