nigerian-phone-validator
Version:
Validate and format a Nigerian phone number
65 lines (46 loc) • 1.5 kB
Markdown
Validate and format Nigerian phone numbers
```
$ npm install nigerian-phone-validator --save
```
This module accepts a regular `11-digits` Nigerian phone number, validate it and then format it using the country code. Example, a phone number given as `08024672344` will be validated and formated to look like this: `+2348024672344`
The `validate` function accepts the phone number as a `string` and then returns an `object` containing information regarding the phone number given like so:
```js
validate("8024672344")
// Return value
{
success: true,
phone: "+2348024672344",
msg: "Phone number validated and formated"
}
```
Always keep your eyes on the `success` property of the return value. Is is a `Boolean` that tells you how successful the validation process went
```js
const validate = require('nigerian-phone-validator')
let phoneObject = validate("08024672344")
console.log(phoneObject)
// Output
{
success: true,
phone: "+2348024672344",
msg: "Phone number validated and formated"
}
// The operation may also error out
let phoneObject = validate("+8024672344")
console.log(invalidNumber)
// Output
{
success: false,
phone: "+8024672345",
msg: "Remove country code symbol from phone number"
}
```
Pull Requests are welcomed, feel free to make the web a better place
MIT
[](https://www.webscrapingzone.com/)