DEV Community

Cover image for How to Generate Realistic Fake Phone Numbers for Test Data
Sanjeev Pulakurthi
Sanjeev Pulakurthi

Posted on Originally published at devtoolstack.io

How to Generate Realistic Fake Phone Numbers for Test Data

Ten random digits is not a phone number

US phone numbers follow the North American Numbering Plan (NANP), and the format XXX-XXX-XXXX has real constraints baked into it:

  • Area code (NPA) — the first digit must be 2–9. 0 and 1 are reserved as trunk prefixes.
  • Exchange / central office code (NXX) — same rule. First digit must be 2–9.
  • N11 codes are reserved — 211, 311, 411, 511, 611, 711, 811, 911 are service codes, not area codes or exchanges.
  • Line numb er — the last four digits are genuinely unconstrained, 0000–9999.

So 073-118-4492 is ten digits and it is not a phone number. Any validator worth using — libphonenumber, most form libraries, the majority of hand-rolled regexes — will reject it. Naive random generation produces an invalid area code roughly 20% of the time, and an invalid exchange another 20% on top of that.

If you're seeding a few hundred rows, that's a meaningful chunk of your fixtures silently failing.

A generator that actually respects the rules (Our Tool)

Screenshot of tool

The wider point about test data

Phone numbers are a small example of a pattern that shows up everywhere in fixtures:

  • Credit card numbers need to pass the Luhn checksum, or your payment form rejects them
  • UUIDs have version and variant bits in fixed positions
  • ISBNs, IMEIs, VINs, and IBANs all carry check digits
  • Even em ail addresses have rules that asdf@asdf quietly violates

Random bytes shaped like the right thing are not the right thing. Any field with a validator on it needs a generator that knows the same rules the validator does — otherwise you're just generating a slower way to fail.

About DevToolStack

The phone generator is one of 118+ free tools on DevToolStack — a collection I built for exactly this kind of small, recurring developer task that doesn't justify writing a script.

Everything runs client-side in your browser. No accounts, no uploads, no limits, and nothing you paste is transmitted to a server — which matters more than it sounds when the thing you're decoding is a JWT from production.

Dev Tool Stack io

A few that get the most use:

Generators — random Base64 and hex strings, UUIDs, PINs, colors, dates, user agents
Data Encoding — Base64, URL, HTML entity encode/decode
Formatters — JSON, SQL, XML
Text Diff Checker — Compare two blocks of text and see line-by-line differences highlighted instantly

Browse all the tools → https://devtoolstack.io/

Top comments (0)