Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weisjohn/nanp
Test if a string is a North American Number Plan (phone) number.
https://github.com/weisjohn/nanp
Last synced: about 2 months ago
JSON representation
Test if a string is a North American Number Plan (phone) number.
- Host: GitHub
- URL: https://github.com/weisjohn/nanp
- Owner: weisjohn
- License: mit
- Created: 2014-04-28T22:46:40.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-08-07T17:23:54.000Z (over 7 years ago)
- Last Synced: 2024-04-23T16:20:37.280Z (9 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nanp
Test if a string is a North American Number Plan (phone) number.
### usage
```javascript
var nanp = require('nanp');nanp("(937) 252 1234"); // returns true
nanp("1 (937) 252 1234"); // returns true
nanp("937.252.1234"); // returns true
nanp("1.937.252.1234"); // returns true
nanp("9372521234"); // returns true
nanp("19372521234"); // returns truenanp("234-911-5678"); // returns false
nanp("123-234-5678"); // returns false
nanp("911"); // returns false```
#### `strip`
You can also use `nanp`'s internal `strip` function to clean strings, removing formatting as well as the country code "1" or "+1":
```javascript
var clean = nanp.strip("1 (937) 252 1234"); // -> 9372521234
```Learn more: http://en.wikipedia.org/wiki/North_American_Numbering_Plan