https://github.com/singuerinc/spain-phone
Spanish phone number validation
https://github.com/singuerinc/spain-phone
call fixed mobile phone phone-number spain validate validation validator
Last synced: 10 months ago
JSON representation
Spanish phone number validation
- Host: GitHub
- URL: https://github.com/singuerinc/spain-phone
- Owner: singuerinc
- License: mit
- Created: 2018-05-18T22:52:39.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-17T11:45:06.000Z (almost 6 years ago)
- Last Synced: 2024-12-08T17:12:54.772Z (over 1 year ago)
- Topics: call, fixed, mobile, phone, phone-number, spain, validate, validation, validator
- Language: JavaScript
- Homepage: https://spain-phone-demo.netlify.com
- Size: 224 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://travis-ci.org/singuerinc/spain-phone)
[](https://coveralls.io/github/singuerinc/spain-phone?branch=master)
:telephone_receiver: Spanish phone number validation
## Installation
```js
// npm
npm i spain-phone
// yarn
yarn add spain-phone
```
## Demo
[https://spain-phone-demo.netlify.com](https://spain-phone-demo.netlify.com)
## Usage
> Note: Replace the x's with numbers
### Check if it is a valid phone number
```js
import { isPhone } from 'spain-phone';
isPhone('907 xx xx xx'); //=> true
```
### Check it is a mobile or fixed number
```js
import { isFixed, isMobile } from 'spain-phone';
isFixed('5xx xx xx xx'); //=> true
isFixed('8xx xx xx xx'); //=> true
isFixed('9xx xx xx xx'); //=> true
isMobile('6xx xx xx xx'); //=> true
isMobile('7xx xx xx xx'); //=> true
```
### State by code / number
```js
import { statesByCode, statesByNumber } from 'spain-phone';
statesByCode('956'); // => ['Cádiz', 'Ceuta']
statesByCode('960'); // => ['Valencia']
statesByCode('93'); // => ['Barcelona']
statesByNumber('956 26 26 08'); // => ['Cádiz', 'Ceuta']);
statesByNumber('960 11 11 11'); // => ['Valencia']);
statesByNumber('934 58 78 60'); // => ['Barcelona']);
```
### Others
```js
import { isFreeCall, isLowCost, isHighCost, isOther } from 'spain-phone';
// paid by who receive the call
isFreeCall('900 xx xx xx'); // => true
// paid 50/50 or at national rate
isLowCost('901 xx xx xx'); // => true
// usually used in tv contest, data system lines and services
isHighCost('905 xx xx xx'); // => true
isHighCost('907 xx xx xx'); // => true
isHighCost('803 xx xx xx'); // => true
isHighCost('806 xx xx xx'); // => true
isHighCost('807 xx xx xx'); // => true
// internet access
isOther('908 xx xx xx'); // => true
isOther('909 xx xx xx'); // => true
// radio-searching
isOther('940 xx xx xx'); // => true
```
## Reference
[https://es.wikipedia.org/wiki/Anexo:Prefijos_telef%C3%B3nicos_de_Espa%C3%B1a](https://es.wikipedia.org/wiki/Anexo:Prefijos_telef%C3%B3nicos_de_Espa%C3%B1a)
## Related
* [better-dni](https://github.com/singuerinc/better-dni) - The fastest Spanish DNI (NIE / NIF) validation