The @flatfile/plugin-validate-phone
plugin offers a convenient way to
validate phone numbers. By setting up an event listener for the commit:created
event, this plugin seamlessly integrates with the data processing flow. This
plugins supports phone number formatting for multiple countries (US, UK, India,
Germany, France, and Brazil).
Event Type:
listener.on('commit:created')
The sheetSlug
parameter is the slug of the sheet you want to listen to. By default it listens to commits in all sheets.
The phoneField
parameter is the phone field's name.
The countryField
parameter is the country field's name.
The autoConvert
parameter allows you to specify whether the field's format will automatically be converted.
The concurrency
parameter allows you to specify the number of records to process concurrently.
The debug
parameter allows you to turn on debug logging.
The format
parameter specifies the desired output format for the phone number. Options include 'NATIONAL', 'INTERNATIONAL', 'E164', 'RFC3966', and 'SIGNIFICANT'.
The formatOptions
parameter allows you to pass additional formatting options as defined by the libphonenumber-js
library.
npm install @flatfile/plugin-validate-phone
import validatePhone from '@flatfile/plugin-validate-phone';
This example sets up a record hook using listener.use
to validate and format phone numbers in the "my-sheet" sheet which contains a phone number field called phone_number
and a country field called country_code
.
import { FlatfileListener } from '@flatfile/listener';
import validatePhone from '@flatfile/plugin-validate-phone';
export default function (listener: FlatfileListener) {
listener.use(validatePhone({
sheetSlug: 'my-sheet',
phoneField: 'phone_number',
countryField: 'country_code',
autoConvert: true,
format: 'INTERNATIONAL',
formatOptions: { formatExtension: 'national' }
}));
// ... rest of your Flatfile listener
}