Package Exports
- phone
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (phone) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Phone ·

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:
+18175698900Install
npm install phoneUsage
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 testOld browsers & browser support
We currently transpile script to base on target env which that browser global usage '>1%' and "node: 6.11.5".
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
Does
phonedo any phone validation?Yes: If you provide the 2nd parameter (country), and the phone number do not start with
+sign.phonewill validatephone_number_lengthsandmobile_begin_withWhy 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.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