项目作者: singuerinc

项目描述 :
Spanish phone number validation
高级语言: JavaScript
项目地址: git://github.com/singuerinc/spain-phone.git
创建时间: 2018-05-18T22:52:39Z
项目社区:https://github.com/singuerinc/spain-phone

开源协议:MIT License

下载


Build Status
Coverage Status

:telephone_receiver: Spanish phone number validation

Installation

  1. // npm
  2. npm i spain-phone
  3. // yarn
  4. yarn add spain-phone

Demo

https://spain-phone-demo.netlify.com

Usage

Note: Replace the x’s with numbers

Check if it is a valid phone number

  1. import { isPhone } from 'spain-phone';
  2. isPhone('907 xx xx xx'); //=> true

Check it is a mobile or fixed number

  1. import { isFixed, isMobile } from 'spain-phone';
  2. isFixed('5xx xx xx xx'); //=> true
  3. isFixed('8xx xx xx xx'); //=> true
  4. isFixed('9xx xx xx xx'); //=> true
  5. isMobile('6xx xx xx xx'); //=> true
  6. isMobile('7xx xx xx xx'); //=> true

State by code / number

  1. import { statesByCode, statesByNumber } from 'spain-phone';
  2. statesByCode('956'); // => ['Cádiz', 'Ceuta']
  3. statesByCode('960'); // => ['Valencia']
  4. statesByCode('93'); // => ['Barcelona']
  5. statesByNumber('956 26 26 08'); // => ['Cádiz', 'Ceuta']);
  6. statesByNumber('960 11 11 11'); // => ['Valencia']);
  7. statesByNumber('934 58 78 60'); // => ['Barcelona']);

Others

  1. import { isFreeCall, isLowCost, isHighCost, isOther } from 'spain-phone';
  2. // paid by who receive the call
  3. isFreeCall('900 xx xx xx'); // => true
  4. // paid 50/50 or at national rate
  5. isLowCost('901 xx xx xx'); // => true
  6. // usually used in tv contest, data system lines and services
  7. isHighCost('905 xx xx xx'); // => true
  8. isHighCost('907 xx xx xx'); // => true
  9. isHighCost('803 xx xx xx'); // => true
  10. isHighCost('806 xx xx xx'); // => true
  11. isHighCost('807 xx xx xx'); // => true
  12. // internet access
  13. isOther('908 xx xx xx'); // => true
  14. isOther('909 xx xx xx'); // => true
  15. // radio-searching
  16. isOther('940 xx xx xx'); // => true

Reference

https://es.wikipedia.org/wiki/Anexo:Prefijos_telef%C3%B3nicos_de_Espa%C3%B1a

  • better-dni - The fastest Spanish DNI (NIE / NIF) validation