# joi-phone-number

> Phone number validation rule for Joi

Latest version **5.1.1** (published 2022-03-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install joi-phone-number
pnpm add joi-phone-number
yarn add joi-phone-number
bun add joi-phone-number
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.1 |
| Published | 2022-03-01 |
| First published | 2017-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/joi-phone-number) |
| Module format | CommonJS |
| Node | >=12.16.0 |
| Dependencies | 1 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 72 |
| Author | Salesflare |
| Maintainers | adrivanhoudt |
| Keywords | joi, extention, phone number, rule |

## Links

- npm: https://www.npmjs.com/package/joi-phone-number
- Repository: https://github.com/Salesflare/joi-phone-number
- Issues: https://github.com/Salesflare/joi-phone-number/issues
- npm.io page: https://npm.io/package/joi-phone-number

## Dependencies (1)

- [google-libphonenumber](https://npm.io/package/google-libphonenumber.md) 3.2.27

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 5.1.1 (latest) — 2022-03-01
- 5.1.0 — 2022-01-14
- 5.0.1 — 2021-02-16
- 5.0.0 — 2020-09-22
- 4.1.2 — 2020-08-14
- 4.1.1 — 2020-06-29
- 4.1.0 — 2020-03-15
- 4.0.1 — 2020-03-15
- 4.0.0 — 2020-01-14
- 3.1.1 — 2019-10-20
- 3.1.0 — 2019-09-25
- 3.0.3 — 2019-08-30
- 3.0.2 — 2019-06-29
- 3.0.1 — 2019-05-27
- 3.0.0 — 2019-05-14
- … 27 more at https://npm.io/package/joi-phone-number/versions

## README

# joi-phone-number

Phone number validation rule for Joi

[![Build Status](https://travis-ci.org/Salesflare/joi-phone-number.svg?branch=master)](https://travis-ci.org/Salesflare/joi-phone-number)
[![Greenkeeper badge](https://badges.greenkeeper.io/Salesflare/joi-phone-number.svg)](https://greenkeeper.io/)

## What

Allows you to do `Joi.string().phoneNumber()`.

Uses [https://github.com/ruimarinho/google-libphonenumber](https://github.com/ruimarinho/google-libphonenumber) for validation.

Which is a compiled version of the Google library [https://github.com/googlei18n/libphonenumber](https://github.com/googlei18n/libphonenumber).

## How

```js
const myCustomJoi = Joi.extend(require('joi-phone-number'));

myCustomJoi.string().phoneNumber().validate('+32494567324');

// The phone number can be transformed to a custom format
// Note that this follows Joi's `convert` option
myCustomJoi.string().phoneNumber({ defaultCountry: 'BE', format: 'e164' }).validate('494322456'); // '+32494322456'
myCustomJoi.string().phoneNumber({ defaultCountry: 'BE', format: 'international' }).validate('494322456'); // '+32 494 32 24 56'
myCustomJoi.string().phoneNumber({ defaultCountry: 'BE', format: 'national' }).validate('494322456'); // '0494 32 24 56'
myCustomJoi.string().phoneNumber({ defaultCountry: 'BE', format: 'rfc3966' }).validate('494322456'); // 'tel:+32-494-32-24-56'
myCustomJoi.string().phoneNumber({ defaultCountry: 'US', strict: true }).validate('7777777777'); // validation error
myCustomJoi.string().phoneNumber({ defaultCountry: 'US'}).validate('7777777777'); // 7777777777
```

---
_Source: https://npm.io/package/joi-phone-number · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
