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_KEYenvironment variable. Ask_test_key returns simulated results and never spends credits: see Test mode. - The key read in a
.server.tsmodule only, so the bundler keeps it out of the browser: see Authentication.
Steps
1. Install the SDK
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.
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:
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.
Related
Frequently asked questions
Where do I keep the API key?
Does this work in React Router 7 framework mode?
What happens if the API is down?
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