Skip to content

Integrations

Validate phone numbers and emails in Google Sheets

Verify a column of emails or phone numbers in Google Sheets with Apps Script and UrlFetchApp, using a menu command or a cached custom function.

Updated 2026-11-23

This recipe adds a Validate menu to a Google Sheet. Select a column of emails or phone numbers, run the command, and the sheet fills two columns next to it with the status and the reason or the normalized number. It uses Apps Script and UrlFetchApp, with no add-on.

What you need

  • A Google account and a sheet with emails or phone numbers in a column.
  • A Qelka API key. A sk_test_ key returns simulated results and never spends credits: see Test mode.
  • Google's Apps Script has daily quotas for URL fetches and a time limit per run. They depend on your account type, so check Google's current quotas before checking thousands of rows. For very large files, use a bulk job instead.

Steps

1. Store the key

Open Extensions, then Apps Script. In Project Settings, scroll to Script Properties and add a property named API_KEY with your key as its value. Script properties stay inside the script project: they do not appear in cells, and people who can only view the sheet cannot read them. Anyone with edit access to the script can, so create a key just for this sheet and restrict it to /batch in the dashboard. See Restricted keys.

2. The script

Replace the contents of Code.gs:

javascript
const BASE_URL = 'https://api.qelka.com/v1'
const BATCH_SIZE = 100

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('Validate')
    .addItem('Check selected emails', 'checkEmails')
    .addItem('Check selected phone numbers', 'checkPhones')
    .addToUi()
}

function checkEmails() {
  checkSelection('email')
}

function checkPhones() {
  checkSelection('phone')
}

function checkSelection(type) {
  const range = SpreadsheetApp.getActiveRange()
  const values = range.getValues().map((row) => String(row[0]).trim())
  const output = []

  for (let start = 0; start < values.length; start += BATCH_SIZE) {
    const chunk = values.slice(start, start + BATCH_SIZE)
    const indexes = []
    const items = []
    chunk.forEach((value, position) => {
      if (value) {
        indexes.push(position)
        items.push({ type, [type]: value })
      }
    })
    const results = items.length ? callBatch(items) : []
    const rows = chunk.map(() => ['', ''])
    results.forEach((entry, position) => {
      rows[indexes[position]] = summarize(type, entry)
    })
    output.push(...rows)
  }

  const target = range.offset(0, 1, output.length, 2)
  target.setValues(output)
  SpreadsheetApp.getActive().toast(`Checked ${values.length} rows`, 'Validate', 5)
}

function summarize(type, entry) {
  if (entry.object === 'error') return ['error', entry.error.type]
  if (type === 'email') return [entry.status, entry.did_you_mean || entry.reason]
  return [entry.status, entry.e164 || '']
}

function callBatch(items) {
  const apiKey = PropertiesService.getScriptProperties().getProperty('API_KEY')
  for (let attempt = 1; attempt <= 4; attempt += 1) {
    const response = UrlFetchApp.fetch(`${BASE_URL}/batch`, {
      method: 'post',
      contentType: 'application/json',
      headers: { Authorization: `Bearer ${apiKey}` },
      payload: JSON.stringify({ items }),
      muteHttpExceptions: true,
    })
    const status = response.getResponseCode()
    if (status === 200) return JSON.parse(response.getContentText()).data
    if ([429, 500, 502, 503].includes(status) && attempt < 4) {
      const retryAfter = Number(response.getHeaders()['Retry-After'])
      Utilities.sleep((retryAfter > 0 ? retryAfter : 2 ** attempt) * 1000)
      continue
    }
    const type = JSON.parse(response.getContentText()).error.type
    throw new Error(`${type} (request ${response.getHeaders()['X-Request-Id']})`)
  }
}

Reload the sheet. A Validate menu appears. Select the cells of the emails, run Check selected emails, and Google asks you to authorize the script the first time.

Each result takes two columns to the right of the selection: the status and then, for emails, did_you_mean or the reason, and for phones, the e164 number. The batch endpoint takes up to 100 items per request and counts as one request, so a long column does not hit the rate limit. See the batch reference.

3. Read the result

Status Meaning What to do
Email deliverable The mail server accepted the mailbox Keep
Email undeliverable Bad syntax, no domain or no mailbox Remove, or fix with the suggestion
Email risky Disposable inbox, catch-all domain or full mailbox Review
Email unknown The checks could not conclude Keep. Do not treat as bad
Phone valid Valid in its numbering plan Use the e164 column
Phone invalid Does not fit the plan Correct the number
Phone unknown No + prefix and no country Write numbers with the +

Add a conditional-formatting rule on the status column to color undeliverable rows. A phone number without a + returns unknown; the script sends no country, so format numbers internationally first.

4. Optional: a cached custom function

javascript
function VALIDATE_EMAIL(email) {
  if (!email) return ''
  const cache = CacheService.getScriptCache()
  const key = `email:${email}`
  const cached = cache.get(key)
  if (cached) return cached
  const results = callBatch([{ type: 'email', email: String(email) }])
  const status = results[0].object === 'error' ? 'error' : results[0].status
  cache.put(key, status, 21600)
  return status
}

Use =VALIDATE_EMAIL(A2) in a cell. The cache lasts six hours, so repeated recalculations do not spend credits, but after that a recalculation checks again. For anything beyond a few cells, use the menu command.

Handle errors and rate limits

The script retries 429, 500, 502 and 503 after Retry-After, then stops with the error type and the request id. 401, 403 and 402 mean a wrong key, a restricted key or an empty balance. A batch item that fails shows error in its row without stopping the rest. Nothing is billed on errors. See Errors and Rate limits. Each email costs 1 credit.

Frequently asked questions

Menu command or custom function?
Prefer the menu command. It checks the selected cells once and writes static values, so nothing is re-checked or re-billed. A custom function recalculates whenever Sheets decides to, and every recalculation can spend credits. The cached custom function below limits that, but the menu command stays the safer choice for lists.
Where do I store the API key?
In Script properties, under Project Settings in the Apps Script editor, with the name API_KEY. Script properties are not visible in the sheet cells and are not copied to people who only view the sheet. Do not paste the key in a cell or in the code, and make a separate key for the spreadsheet.
Is there a limit on how many rows I can check?
Google limits how many URL fetch calls a script can make per day and how long one run may take, and the limits differ by account type. Check Google's current quotas. The script below sends up to the batch maximum of values in one request, which uses far fewer fetches than one call per row.

Put this check in your product

Get an API key in under a minute. 100 free credits every month, no card required.

  • 100 free credits a month
  • No card
  • Test keys spend nothing
  • Cancel any time