[go: up one dir, main page]

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