All Projects → AfterShip → Phone

AfterShip / Phone

Licence: mit
With a given country and phone number, validate and reformat the mobile phone number to the E.164 standard. The purpose of this is to allow us to send SMS to mobile phones only.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Phone

Moriarty Project
This tool gives information about the phone number that you entered.
Stars: ✭ 223 (-58%)
Mutual labels:  phone, sms, phone-number
Crboxinputview
Verify code input view. Support security type for password.短信验证码输入框,支持密文模式
Stars: ✭ 749 (+41.05%)
Mutual labels:  phone, phone-number, mobile
Reborn
ReborN SMS BOMBER | SpeedX & 4NAT
Stars: ✭ 126 (-76.27%)
Mutual labels:  phone-number, sms
woapp
web模拟安卓操作系统,php开发,内置文件管理,电话,短信,拍照,用在树莓派上可做智能家居,视频监控,机顶盒等……
Stars: ✭ 22 (-95.86%)
Mutual labels:  phone, sms
Vonage Node Sdk
Vonage API client for Node.js. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 323 (-39.17%)
Mutual labels:  phone, sms
botkit-sms
Twilio Programmable SMS implementation for Botkit.
Stars: ✭ 18 (-96.61%)
Mutual labels:  phone-number, sms
PhoneNumberKit
Android Kotlin library to parse and format international phone numbers. Country code picker.
Stars: ✭ 124 (-76.65%)
Mutual labels:  phone-number, phone
laravel-authy
Rinvex Authy is a simple wrapper for @authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
Stars: ✭ 35 (-93.41%)
Mutual labels:  phone, sms
keycloak-phone-provider
A Keycloak provider which phone and SMS
Stars: ✭ 83 (-84.37%)
Mutual labels:  phone, sms
Twilio Java
A Java library for communicating with the Twilio REST API and generating TwiML.
Stars: ✭ 371 (-30.13%)
Mutual labels:  phone, sms
Gammu
Gammu All Mobile Management Utilities
Stars: ✭ 366 (-31.07%)
Mutual labels:  sms, mobile
Vue Phone Number Input
A phone number input made with Vue JS (format & valid phone number)
Stars: ✭ 407 (-23.35%)
Mutual labels:  phone, phone-number
node-identif
🔑 Helper class to verify one's identity via personal channels(SMS, Phone, E-Mail and more!)
Stars: ✭ 27 (-94.92%)
Mutual labels:  phone, sms
getcontact
Find info about user by phone number using GetContact API
Stars: ✭ 228 (-57.06%)
Mutual labels:  phone-number, phone
PokerTexter
SMS App for Poker Odds. Runs on Flask + Twilio + Heroku.
Stars: ✭ 17 (-96.8%)
Mutual labels:  phone, sms
node-gsm
📲 gsm modem module for node.js
Stars: ✭ 23 (-95.67%)
Mutual labels:  phone, sms
haoma
手机固话电话号码标记批量查询📞📌
Stars: ✭ 52 (-90.21%)
Mutual labels:  phone-number, phone
Phonia
Phonia Toolkit is one of the most advanced toolkits to scan phone numbers using only free resources. The goal is to first gather standard information such as country, area, carrier and line type on any international phone numbers with a very good accuracy.
Stars: ✭ 221 (-58.38%)
Mutual labels:  phone, phone-number
Mobly
E2E test framework for tests with complex environment requirements.
Stars: ✭ 424 (-20.15%)
Mutual labels:  phone, mobile
Cht Core
The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
Stars: ✭ 354 (-33.33%)
Mutual labels:  phone, mobile

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

or

yarn add phone

Demo

Try it on CodeSandbox

Usage

const phone = require('phone');

phone('+852 6569-8900'); // return ['+85265698900', 'HKG']
phone('+1(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('6123-6123', 'HKG'); // return ['+85261236123', 'HKG']

Without country code and no phone prefix

If both country code and country phone prefix are not provided, will treat as USA or Canada by default

phone('(817) 569-8900'); // return ['+18175698900, 'USA']
phone('(817) 569-8900', ''); // return ['+18175698900, 'USA']
phone('(817) 569-8900', ''); // return ['+18175698900', 'USA']
phone('780-569-8900', ''); // return ['+17805698900, 'CAN'], 780 is a Canada phone prefix
phone('6123-6123', ''); // return [], as default country is USA / CAN and it does not match any result

Even you input a valid phone number with a valid prefix, if there is no plus sign, it will not work as expected:

phone('85291234567', '')

852 is a valid Hong Kong phone prefix, and 91234567 is a valid Hong Kong mobile phone number. However, there is no plus sign provided, the module will assume the phone number is a USA or Canada phone number, hence no result will be found.

If you know you have provided country phone prefix, make sure you also provide a plus sign:

phone('+85291234567', '')

// return [ '+85291234567', 'HKG' ]

or, if you know the country, and only want to reformat the phone number to E.164 format:

phone('91234567', 'HKG')

// return [ '+85291234567', 'HKG' ]

Skipping phone number initial digit checking

If you want to skip phone number initial digit checking, set allowLandline to true:

phone('+(852) 2356-4902', '', true);

And the initial digit checking will be disabled completely, even you enter a phone number start with a non-exist digit:

phone('+(852) 0356-4902', '', true); // return [ '+85203564902', 'HKG' ], even the phone number start with `0` is not a valid landline phone number

API

const phone = require('phone');

phone(phone: String, [country: string, allowLandline: Boolean]): Array

Input

Parameter Type Required Description
phone String Yes The phone number text you want to process
country String No Provided country code in iso-3166 alpha 2 or 3 format
allowLandLine Boolean No Set to true if you want to skip phone number initial digit checking

Returns

The return would always be an Array

Array index Type Description
0 String Normalized phone number in E.164 format
1 String Detected phone number country code in iso-3166 alpha 3 format

If the phone number cannot be reformatted due to any reason (e.g. unable to match any country), the result would be an empty array.

The function response is in Array format for some historical reason and expected to be updated to a proper object response in the next major version bump. (Will not change on version 2.x)

Test

yarn 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?

    By default, the function will validate a mobile phone number only, to validate a landline phone number, please set 3rd parameter allowLandline to true.

    If you find the result is still incorrect, please submit a ticket to improve our validation rules.

  3. How does allowLandline work?

    Mobile phone number detection is achieved by comparing the beginning digits of a phone number to a list of possible mobile prefixes for a country. In some countries, some or all of these prefixes are the same for both mobile phones and landlines; when allowLandline is set to false you should not assume that all possible landline phone numbers will be reliably filtered out.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].