BR Phone Number Validation Function Documentation

The validateBRPhoneNumber function is used to validate Brazilian phone numbers. It returns an object with two properties: "isValid" (boolean) and "errorMsg" (string). The "errorMsg" property will contain the error message if the phone number is invalid, or it will be null if the phone number is valid.

Import

The function can be imported using ES6 syntax from the "validateBRPhoneNumber" package:

import { validateBRPhoneNumber } from 'multiform-validator';

Alternatively, you can import the function using CommonJS syntax with require (Node.js):

const { validateBRPhoneNumber } = require('multiform-validator');

Parameters

The function takes two parameters:

Default Error Messages

The default error messages are as follows:

[
	'Invalid value passed',
	'Invalid phone number',
	'Unknown error'
]

Examples

const result1 = validateBRPhoneNumber('(11) 98765-4321');
console.log(result1);
// Output: { isValid: true, errorMsg: null }

const customErrorMsg = ['Invalid format', 'Invalid phone number', 'Unknown error'];
const result2 = validateBRPhoneNumber('(11) 98765-4321', customErrorMsg);
console.log(result2);
// Output: { isValid: true, errorMsg: null }

const result3 = validateBRPhoneNumber('invalid');
console.log(result3);
// Output: { isValid: false, errorMsg: 'Invalid value passed' }

const result4 = validateBRPhoneNumber('(11) 1234-5678', customErrorMsg);
console.log(result4);
// Output: { isValid: false, errorMsg: 'Invalid phone number' }