Skip to content

Integrations

Validate phone numbers and emails in Remix

Check emails, phone numbers and IPs in a Remix or React Router action with the SDK. Return field errors, flag risky signups and fail open on API errors.

Updated 2026-11-23

This recipe validates a signup form inside a Remix action. The email, phone number and client IP are checked on the server, field errors go back to the form and an API outage never blocks a signup.

What you need

  • A Remix 2 or React Router 7 app on Node.js 20 or later.
  • A Qelka API key in the API_KEY environment variable. A sk_test_ key returns simulated results and never spends credits: see Test mode.
  • The key read in a .server.ts module only, so the bundler keeps it out of the browser: see Authentication.

Steps

1. Install the SDK

bash
npm install @qelka/sdk

2. The validation module

Save as app/validate-signup.server.ts. The .server suffix keeps the file, and the key, out of the client bundle.

typescript
import { ApiConnectionError, ApiError, Client } from '@qelka/sdk'

const client = new Client({ apiKey: process.env.API_KEY as string, timeoutMs: 8000 })

export type Verdict = {
  errors: Record<string, string>
  checked: boolean
  e164: string | null
  review: boolean
}

export async function validateSignup(input: {
  email?: string
  phone?: string
  country?: string
  ip?: string
}): Promise<Verdict> {
  const verdict: Verdict = { errors: {}, checked: true, e164: null, review: false }

  const settle = async (task: () => Promise<void>) => {
    try {
      await task()
    } catch (error) {
      if (error instanceof ApiError && error.type === 'unprocessable_input') return
      if (!(error instanceof ApiError) && !(error instanceof ApiConnectionError)) throw error
      verdict.checked = false
      console.error('validation skipped', error instanceof ApiError ? `${error.type} ${error.requestId}` : 'unreachable')
    }
  }

  await Promise.all([
    input.email &&
      settle(async () => {
        const result = await client.email.verify({ email: input.email as string })
        if (result.status === 'undeliverable') {
          verdict.errors.email = result.did_you_mean ? `Did you mean ${result.did_you_mean}?` : 'This email address cannot receive mail.'
        } else if (result.status === 'risky' && result.reason === 'disposable') {
          verdict.review = true
        }
      }),
    input.phone &&
      settle(async () => {
        const result = await client.phone.validate({ phone: input.phone as string, country: input.country })
        if (result.status === 'valid') verdict.e164 = result.e164
        if (result.status === 'invalid') verdict.errors.phone = 'This phone number is not valid.'
      }),
    input.ip &&
      settle(async () => {
        const result = await client.ip.lookup({ ip: input.ip as string })
        if (result.risk.level === 'high' || result.flags.tor) verdict.review = true
      }),
  ])
  return verdict
}

3. The route

Save as app/routes/signup.tsx:

tsx
import type { ActionFunctionArgs } from '@remix-run/node'
import { json } from '@remix-run/node'
import { Form, useActionData } from '@remix-run/react'
import { validateSignup } from '~/validate-signup.server'

export async function action({ request }: ActionFunctionArgs) {
  const form = await request.formData()
  const email = String(form.get('email') ?? '')
  const phone = String(form.get('phone') ?? '')
  const forwarded = request.headers.get('x-forwarded-for')

  const verdict = await validateSignup({
    email,
    phone,
    country: String(form.get('country') ?? '') || undefined,
    ip: forwarded?.split(',')[0]?.trim(),
  })

  if (Object.keys(verdict.errors).length > 0) return json({ errors: verdict.errors }, { status: 422 })

  await createUser({ email, phone: verdict.e164 ?? phone, needsReview: verdict.review, needsRecheck: !verdict.checked })
  return json({ errors: {} }, { status: 201 })
}

export default function Signup() {
  const data = useActionData<typeof action>()
  return (
    <Form method="post">
      <input name="email" type="email" required />
      {data?.errors.email ? <p role="alert">{data.errors.email}</p> : null}
      <input name="phone" type="tel" />
      {data?.errors.phone ? <p role="alert">{data.errors.phone}</p> : null}
      <button type="submit">Sign up</button>
    </Form>
  )
}

createUser is your own function. Take the client address from the header that your host sets and trust it only when the request really came through your proxy. Store e164 instead of what was typed.

Read the result

Result Action
Email undeliverable Reject with 422, show did_you_mean
Email risky, reason disposable Flag, or reject if you block disposable inboxes
Email unknown Accept and confirm by email
Phone valid Store e164
Phone unknown No + and no country: send the country
IP high risk or Tor Flag for review, add friction

Handle errors and rate limits

No error is billed. The SDK retries 429, 502 and 503 responses, waiting Retry-After when present. After 200 requests per 10 seconds on one key you get 429 rate_limited. 401 invalid_api_key and 403 forbidden mean a wrong or restricted key. 402 insufficient_credits means an empty balance: alert yourself and keep failing open. Each email check costs 1 credit. See Errors and Rate limits.

Frequently asked questions

Where do I keep the API key?
In an environment variable read only on the server, here a server module that reads process.env. Never put it in code, in a client bundle or in a variable that your framework exposes to the browser. Use a separate key for development and production, and a sk_test_ key while you build.
Does this work in React Router 7 framework mode?
Yes. Remix and React Router framework mode share the same action and loader model, so the code is the same. Only the import path for the action arguments differs: use the package your project already imports from, and keep the validation module in a .server file.
What happens if the API is down?
The signup goes through. A failed call never produces a form error: only a clear negative answer, such as an undeliverable email or an invalid phone number, rejects the request. The verdict records that the check did not run, so a background job can re-check the account later.

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