Skip to content

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

License

Notifications You must be signed in to change notification settings

jlozovei/validate-ddd-br

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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). πŸ‡§πŸ‡· ☎️

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published