Validate Phone Numbers with Functions

Evervault Functions are secure, isolated serverless functions that can be used to process encrypted data.

In this guide, you will use Evervault Functions to validate encrypted phone numbers, normalize the formatting of the phone number, and then return the encrypted and normalized phone number alongside a validity check — something that would normally be impossible to do on encrypted data.

Setting up your Evervault Account

Before creating an Evervault Function, you’ll need to have an Evervault account. If you haven’t done so already you can sign up at Once your account is set up you’ll need to create an App, to do so, just click the Create App button in the Evervault dashboard.

Setting up the Evervault CLI

Functions are either managed through Github, or the Evervault CLI. In this guide, you will create a Function using the CLI, however, you can check out the docs for Evervault Functions to learn more about how to set one up through Github.

Run the command below in your terminal of choice to download and install the Evervault CLI.

Next, you’ll need to login and select your team and app. Just run the command below and follow the prompts to get signed in.

Create your Function

The Evervault CLI has a Function quickstart command. The command below will initialize a Function in your current directory.

To follow this tutorial, be sure to select node as your Function’s language.

Next, you’ll need to install the phone library from npm.

Now open up index.js in your favourite code editor and replace it with the following:

The code above validates and formats a phone number for the country provided when it is invoked. The formatted phone number is then returned from the function as an Evervault-encrypted string within the encryptedPhoneNumber value.

Deploying your Function

To deploy the Function, run the following command:

The deploy command is also used to make updates to an existing Function.

Running your Function

When you run your Function, any encrypted data present in the request is automatically decrypted before it reaches your code. You can also pass plaintext data to a Function alongside encrypted data.

To run your Function using the CLI, run the following command:

The CLI will attempt to run a Function that has been deployed from the directory that it is currently in. If you wish to invoke it from outside of that directory, you will need to pass an additional --name parameter.

If the phone number and country code combination you provided is valid, then isValid will equal true, and there will be an encrypted phone number returned.

You can pass this encrypted phone number back into the Function to see how it works on encrypted data.