Creating a Function

Verifying phone numbers with a Function.

The magic of Evervault is that although you never handle sensitive data in plaintext, you can still use and process it — without the risk of it being breached. This is where Evervault Functions come in. Functions are isolated serverless functions hosted on Evervault for processing the data you encrypt with Relay.

Now we’re going to create and deploy a Function to verify that the phone numbers submitted to your form are valid.

Creating a Function

First, in the Evervault Dashboard, create a Function using our GitHub integration. Select Choose template and, then, authenticate with GitHub. For this, you’ll need a GitHub account — so, create a GitHub account if you haven't got one already. Once you’ve authenticated with GitHub, you can select the ‘Verify Phone’ Function template. This will automatically deploy a Function on Evervault and create a repository in your GitHub. We recommend naming the repo 'verify-phone-number'.

Create a Function

Navigate to your new repo in GitHub (the URL is available on your Function's page in the Evervault Dashboard). You’ll notice that the index.js file contains the following code:

const { phone: validatePhone } = require('phone');
exports.handler = async ({ phone }) => {
const { isValid, countryIso2: country } = validatePhone(phone);
return {

Verifying phone numbers

This Function uses the phone library to validate the phone number and returns the result.

Now that you know what the Function does, it’s time to run it. Update the try block of your POST /submit handler to contain the following:

// Extract name and phone from the JSON the user sends from the form
const { name, phone } = req.body;
console.log('Sending SMS for', { name, phone });
// Verify phone number using a Function
// Will return a result including valid true:false,
// as well as country code information
const { result } = await'verify-phone-number', { phone });
// If the phone number is valid, send the SMS through Twilio
if (result.isValid) {
} else {
// If the phone number is not valid, return an error to the user
console.log('Phone number not valid');
return res.json({ success: false });
return res.json({ success: true });

Note: If you did not name your GitHub repo 'verify-phone-number', make sure you reference the correct repo in this snippet of code.

Complete the form hosted on your Relay domain again. In the Replit console, you should see Verified or an error message returned. Notice that the phone number remains encrypted in the Console log.

Let’s summarize where you are. You’ve:

  1. Created an Express.js server (index.js),
  2. Created a HTML form for collecting a name and a phone number from a user (index.html),
  3. Connected your form to your server,
  4. Integrated Evervault Relay so that phone numbers submitted to your form are encrypted before they enter your server,
  5. Included the Evervault SDK so that outbound requests from your server are automatically decrypted, and
  6. Deployed a Function to verify that phone numbers are valid.

Great! Now that you've used a Function to verify the user's phone number, it’s time to use Twilio to send them an SMS.

Was this page useful?