Make the country registry the safety boundary

A country calling code or valid-looking national format does not make a number fictional. A generator should keep its allowlist separate from its formatting rules. Add an entry only when an official authority identifies a specific range for fiction, drama or another non-live example use, and store the source URL beside that entry.

For example, NANPA identifies the 555-0100 through 555-0199 line-number block as reserved for entertainment and advertising. That statement does not make every number containing 555 fictional. Ofcom publishes the UK mobile drama range 07700 900000 through 07700 900999. These are bounded examples for content and software fixtures; they are not destinations for a delivery or verification test.

Use explicit range records and reject missing countries

Store the permitted range, formatter, source and delivery policy together. Generate a slot only after looking up a country code in that registry. The example below supports two documented examples; its small allowlist is intentional. Add another country only after reviewing its official source.

const FICTION_RANGES = {
  US: {
    size: 100,
    source: "https://www.nanpa.com/numbering/555-line-numbers",
    format: (slot) => "202-555-01" + String(slot).padStart(2, "0")
  },
  GB: {
    size: 1000,
    source: "https://www.ofcom.org.uk/phones-and-broadband/phone-numbers/numbers-for-drama",
    format: (slot) => "07700 900" + String(slot).padStart(3, "0")
  }
};

function fictionalFixture(country, slot) {
  const range = FICTION_RANGES[country];
  if (!range) {
    throw new Error("NO_DOCUMENTED_FICTION_RANGE:" + country);
  }
  if (!Number.isInteger(slot) || slot < 0 || slot >= range.size) {
    throw new RangeError("FICTION_RANGE_SLOT_OUT_OF_BOUNDS");
  }

  return {
    country,
    value: range.format(slot),
    source: range.source,
    fictionalOnly: true,
    deliveryAllowed: false
  };
}

Keep the returned metadata with the fixture. A later caller should not have to infer whether a value is synthetic from its shape. The deliveryAllowed: false field gives downstream code an explicit guard to check before any messaging path is considered.

To select an example at random, choose a slot from 0 through size - 1 with a bounded integer generator, then pass that slot to fictionalFixture. For reproducible automated tests, pass a fixed slot instead. Random selection and fictional status are separate: the registry grants the safety property; randomness only chooses among its entries.

Test the rejection path as carefully as a successful example

A pleasant demo with two supported countries can hide an unsafe fallback. Add tests that pin both the output and the boundary:

  • For US slots 0 and 99, expect 202-555-0100 and 202-555-0199; for GB slots 0 and 999, expect 07700 900000 and 07700 900999.
  • Reject slot -1 and a slot equal to the range size. Do not wrap, clamp or generate a number outside the documented block.
  • Request a country absent from the registry, such as DE in this example, and assert NO_DOCUMENTED_FICTION_RANGE. Assert that no value is returned.
  • Assert every returned fixture has fictionalOnly === true and deliveryAllowed === false.
  • Stub the range registry to empty in one test and prove the user interface shows “no documented fictional range” rather than a plausible-number fallback.

When you add a new source, review whether its range is current, geographically scoped and expressly designated for fictional use. Store a reviewed-on date and registry version so a changed authority page triggers maintenance instead of silently changing an existing fixture.

Keep display fixtures away from real delivery checks

Reserved examples can help render forms, screenshots, help pages and parser cases. They do not prove number assignment, ownership, reachability or receipt of a one-time code. When the country is unsupported, use an unmistakable placeholder such as [TEST PHONE — NO DELIVERY] for documentation, or use your provider's sandbox for an authorized delivery test. Do not replace the error with a realistic-looking number.

This country-specific implementation recipe complements the fictional phone number range review and the broader safe phone number test data guide, which explain source coverage and fixture design.

Use a fake number generator for safe test data

If you need to generate a fake number for a mockup, parser test, or UI fixture, choose only a country range explicitly reserved for fiction. This page's fake number generator returns synthetic examples from the documented US and UK ranges above; each result is marked fictional and not deliverable. A generated sample cannot receive calls, SMS, or verification codes.

When no documented range exists, return the explicit unsupported-region error or use your provider's sandbox for an authorized delivery test. Never replace the error with a plausible real-looking number.

Questions developers ask

Are all phone numbers containing 555 fictional?

No. NANPA reserves the 555-0100 through 555-0199 block for entertainment and advertising. Treat only a specifically documented reserved range as fictional; the digits “555” alone are not a safety rule.

What should a fake phone number generator do for a country without a documented range?

Return a clear unsupported-range error or an unmistakable non-phone placeholder. Do not generate a plausible national number as a fallback. An engineering question about larger NANP test ranges illustrates why this boundary should be explicit, but a forum discussion is not an official numbering allocation.

Can a fictional example receive a verification code?

No. A fictional range is for safe display and software fixtures, not live verification. Use a provider sandbox or a test line you are authorized to use for delivery behavior.

Sources