0

Validate phone number

by
Published Apr 8, 2025

Foxentry allows you to check validity and the existence of phone numbers.

Script foxentry Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Foxentry = {
3
  apiKey: string;
4
};
5
/**
6
 * Validate phone number
7
 * Foxentry allows you to check validity and the existence of phone numbers.
8
 */
9
export async function main(
10
  auth: Foxentry,
11
  api_version: string | undefined,
12
  foxentry_include_request_details: string | undefined,
13
  body: {
14
    request: {
15
      customId?: string;
16
      query: { prefix: string; number: string } | { numberWithPrefix: string };
17
      options?: {
18
        validationType?: "basic" | "extended";
19
        allowedPrefixes?: string[];
20
        preferredPrefixes?: string[];
21
        defaultPrefix?: string;
22
        formatNumber?: false | true;
23
      };
24
      client?: {
25
        ip?: string;
26
        country?: string;
27
        location?: { lat?: number; lon?: number };
28
      };
29
    };
30
  },
31
) {
32
  const url = new URL(`https://api.foxentry.com/phone/validate`);
33

34
  const headers: Record<string, string> = {
35
    "Content-Type": "application/json",
36
    Authorization: "Bearer " + auth.apiKey,
37
  };
38

39
  if (api_version) {
40
    headers["api-version"] = api_version;
41
  }
42
  if (foxentry_include_request_details) {
43
    headers["foxentry-include-request-details"] = foxentry_include_request_details;
44
  }
45

46
  const response = await fetch(url, {
47
    method: "POST",
48
    headers,
49
    body: JSON.stringify(body),
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57