jlozovei / validate-ddd-br

A nice JS package to validate brazilian phone number's area code (DDD). πŸ‡§πŸ‡· :phone:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

validate-ddd-br

A nice JS package to validate the existence of a brazilian phone number's area code (called DDD). πŸ‡§πŸ‡· ☎️

codecov Release

πŸ“• Usage

First things first - install the package using npm or yarn:

# using npm
npm i validate-ddd-br

# using yarn
yarn add validate-ddd-br

After that, import the helper wherever you want to use it:

// es-modules
import { validateDDD } from 'validate-ddd-br';

// commonjs
const validateBrazilianDDD = require('validate-ddd-br');

Then, you'll be able to use it:

πŸ”¬ Validation

// with integer value
const isValid = validateDDD(41); // true
// commonjs = const isValid = validateBrazilianDDD.validateDDD(41);

// with string value
const isValid = validateDDD('41'); // true
// commonjs = const isValid = validateBrazilianDDD.validateDDD('40');

// or with a phone number - it must be provided within a mask to work!
const isValid = validateDDD('(12) 99999-9999'); // true
// commonjs = const isValid = validateBrazilianDDD.validateDDD('(12) 99999-9999');

πŸ“ Localization

It can also tell from where in Brazil the DDD is:

import { isFrom } from 'validate-ddd-br';

const whereFrom = isFrom('21'); // { region: 'Rio de Janeiro', state: 'RJ' }
// commonjs = const isValid = validateBrazilianDDD.isFrom('21');

const whereFrom = isFrom('(31) 99999-9999'); // { region: 'Belo Horizonte', state: 'MG' }
// commonjs = const isValid = validateBrazilianDDD.isFrom('(31) 99999-9999');

Important: both methods accept phone numbers, but you must provide them within the following mask: (xx) xxxxx-xxxx

πŸ’» Developing

First, fork the project. After it, install the dependencies (preferably using npm - since the project is using it) and do the work.

Also, take a look at the contributing guide!

πŸ” License

Licensed under the MIT.

About

A nice JS package to validate brazilian phone number's area code (DDD). πŸ‡§πŸ‡· :phone:

License:MIT License


Languages

Language:JavaScript 99.0%Language:Shell 1.0%