Phone
Test a phone number regex against real numbers
Run a preset or your own pattern over a list of numbers and see where it accepts invalid ones or rejects valid ones, compared with libphonenumber.
Runs in your browserNothing you paste or open here leaves this page. No account, no daily limit.
- Numbers tested
- 14
- Matched by the regex
- 3
- Valid for libphonenumber
- 7
- Regex and library agree
- 8
- False positives
- 1
- False negatives
- 5
False positives are numbers the pattern accepts but the numbering plan rejects (1); false negatives are valid numbers it rejects (5).
| Number | Regex match | Valid | Verdict |
|---|---|---|---|
| +12015550123 | Match | Valid | Match and valid |
| +1 201-555-0123 | Match | Valid | Match and valid |
| (415) 555-0132 | Match | Invalid | False positive |
| +44 7400 123456 | No match | Valid | False negative |
| 07400 123456 | No match | Invalid | No match and invalid |
| +33 6 12 34 56 78 | No match | Valid | False negative |
| +49 1512 3456789 | No match | Valid | False negative |
| +91 81234 56789 | No match | Valid | False negative |
| +81 90-1234-5678 | No match | Valid | False negative |
| +1 123-456-7890 | No match | Invalid | No match and invalid |
| +44 7400 1234 | No match | Invalid | No match and invalid |
| 000-000-0000 | No match | Invalid | No match and invalid |
| +999 123 456 789 | No match | Invalid | No match and invalid |
| 555-1234 | No match | Invalid | No match and invalid |
/^(?:\+?1[\s.-]?)?\(?[2-9]\d{2}\)?[\s.-]?[2-9]\d{2}[\s.-]?\d{4}$/- API access
- Unlock with a free account
How to read the result
Pick a preset or write your own pattern, then run it over the sample list or your own numbers. Each row compares two answers: does the regex match, and does libphonenumber consider the number valid.
| Column | What it means | What to do with it |
|---|---|---|
| Number | The line you entered, trimmed. | Empty lines are skipped. |
| Regex match | Whether your pattern matches the whole line, as RegExp.test() reports it. |
Without ^ and $, a pattern can match part of a line. |
| Valid | Whether libphonenumber, with its full metadata, considers the number valid. | The reference the regex is judged against. |
| Match and valid | Both accept the number. | Fine. |
| No match and invalid | Both reject it. | Fine. |
| False positive | The regex matches, libphonenumber says invalid. | Bad data your pattern lets through. |
| False negative | The regex rejects, libphonenumber says valid. | A real number your pattern turns away. |
| API access | Locked. Validation, line type and carrier from your code. | Needs a free account. |
The counts above the rows add up each kind. A pattern with many false negatives blocks real users, which is usually worse than letting a few bad numbers through to a proper validation step.
How the tester works
- Your pattern is compiled by the browser's JavaScript RegExp engine. If it does not compile, the error message is shown instead of results.
- The flags you type are filtered:
d,i,m,s,uandvare kept,gandyare dropped, since they maketest()remember its position between rows. - Each line of your list, up to 500, is trimmed and tested against the pattern.
- The same line is parsed by libphonenumber-js with its
maxmetadata, built from Google's libphonenumber, and checked with isValid. A number written without + has no country of its own, so libphonenumber can only call it valid once it knows the country: write test numbers with their + when you can. - The two answers are compared row by row.
Everything runs in your browser. No number is sent to a server, there is no account, and no daily limit.
The presets, one by one
Each preset is a pattern you will find in real code. The tester shows where each one stops matching reality.
E.164
^\+[1-9]\d{1,14}$
A plus sign, a first digit from 1 to 9, and up to 15 digits in total, the length limit set by ITU-T Recommendation E.164. It is the right gate for data that was already normalized, such as an e164 field returned by an API. On raw input it fails twice: it rejects +44 7400 123456 because of the spaces, and it accepts +11234567890 (no area code starts with 1), +4474001234 (too short for the UK) and +999123456789 (999 is not an assigned country code), all of which libphonenumber rejects.
North American numbers (NANP)
^(?:\+?1[\s.-]?)?\(?[2-9]\d{2}\)?[\s.-]?[2-9]\d{2}[\s.-]?\d{4}$
An optional +1, then a three-digit area code and a three-digit exchange that both start with 2 to 9, then four digits, with optional parentheses, spaces, dots or hyphens. It correctly rejects +1 123-456-7890. It accepts (370) 555-0123, an area code that is not assigned, and (211) 555-0123, an N11 dialing code, which libphonenumber both rejects. Its parentheses are independent, so (201 555-0123 matches too. It rejects +1 201 555 0123 ext 5, a valid number with an extension.
UK mobile
^(?:\+44\s?7\d{3}|07\d{3})\s?\d{3}\s?\d{3}$
+44 7 or 07, then ten digits after the 0 in groups. It matches +44 7400 123456 and 07400 123456. It also matches +44 7012 345678, a personal number in the UK plan, and +44 7640 123456, in a pager range: both valid, neither a mobile, which the tester cannot flag because it compares validity, not type. It rejects +44 (0)7400 123456 and 0044 7400 123456, both valid ways to write the same mobile.
France
^(?:\+33\s?|0)[1-9](?:[\s.-]?\d{2}){4}$
+33 or the trunk 0, a digit from 1 to 9, then four pairs of digits with optional separators. It matches the usual 06 12 34 56 78 and +33 1 23 45 67 89. It accepts +33 7 00 00 00 00, which libphonenumber rejects, and it lets through premium-rate 08 99 numbers and VoIP 09 numbers along with mobiles and landlines. It rejects +33 (0)6 12 34 56 78 and 0033 6 12 34 56 78.
India mobile
^(?:\+91[\s-]?)?[6-9]\d{4}[\s-]?\d{5}$
An optional +91, then ten digits starting with 6 to 9. It matches +91 81234 56789. It also matches +91 6123456789, which libphonenumber's metadata types as a fixed line, not a mobile. It rejects 09812345678, a mobile written with the trunk 0 that libphonenumber accepts when the default country is India, and every landline such as +91 11 2345 6789, which a mobile pattern is meant to reject but which the tester counts as a false negative because the number is valid.
Loose international
^\+?[\d\s().-]{7,20}$
An optional plus sign, then 7 to 20 characters among digits, spaces, parentheses, dots and hyphens. It almost never turns away a real number, which is its purpose, and it accepts a lot: +1 123-456-7890, +44 7400 1234, 000-000-0000, +999 123 456 789 and 555-1234 from the sample list. It even matches a line of seven parentheses, since nothing in it requires a digit.
What the sample list shows
The sample list mixes valid numbers from six countries with common mistakes. These rows tell the story whatever the default country:
| Number | Valid | Presets that match it |
|---|---|---|
| +12015550123 | Yes | E.164, NANP, loose |
| +1 201-555-0123 | Yes | NANP, loose |
| +44 7400 123456 | Yes | UK mobile, loose |
| +91 81234 56789 | Yes | India mobile, loose |
| +81 90-1234-5678 | Yes | Loose only |
| +1 123-456-7890 | No | Loose |
| +44 7400 1234 | No | Loose |
| +999 123 456 789 | No | Loose |
| 000-000-0000 | No | Loose |
| 555-1234 | No | Loose |
Two patterns emerge. Strict presets reject valid numbers as soon as the formatting or the country differs from what their author expected: the Japanese mobile matches no country preset. The loose preset accepts every valid number and every invalid one in the list. No pattern gets both columns right, because the information needed is not in the characters.
Why a regex is a format gate, not validation
Validity is a property of numbering plans, and plans are data:
- Ranges are assigned piece by piece. A plan says which leading digits are in use for which service. The NANP alone has hundreds of area codes, assigned and retired over decades. A pattern that encodes them is a copy of a list, and copies go stale.
- Lengths differ inside one country. German landline numbers vary in length with the area code, so
+49 30 123456and much longer numbers are both valid. - The same leading digits mean different services. UK 07 covers mobiles, personal numbers and pagers. French 08 covers toll-free, shared-cost and premium-rate numbers.
- Plans change. Regulators open ranges and close them, and the metadata follows with each release. A regex in your code does not update itself.
- People write numbers in many ways. Trunk prefixes, (0), 00 or 011, extensions, dots and slashes all appear in real input.
libphonenumber keeps these rules as metadata maintained from national plans. A regex is the right tool for something smaller: checking that input has a plausible shape before the real check.
Where a regex still belongs
| Job | Good pattern | Then |
|---|---|---|
| Live feedback while someone types | Loose, such as the loose preset | Parse and validate when the field is submitted. |
| Rejecting obvious junk in an import | Loose, plus a minimum digit count | Validate the survivors in bulk. |
| Checking normalized data | E.164 | Nothing more if the data came from a validator. |
| Finding numbers in text | A loose candidate pattern | Validate each candidate with a parser. |
| Routing by country | None: use the parsed country code | Route on the country field of the parse result. |
A sound pipeline for a signup form looks like this:
- Accept the input with a loose check, so nobody is blocked by formatting.
- Parse it with libphonenumber, with the country of the user's address or storefront as the default country.
- Refuse invalid numbers with a clear message, and store the E.164 form of valid ones.
- Check the line type if you send SMS, and call the API when you need the current carrier.
The guide Validate signup forms shows this in code.
Write your own pattern
If you need a pattern anyway, for a database constraint or a legacy system, test it here with inputs that break patterns:
| Input to add to your test list | What it catches |
|---|---|
| +44 (0)7400 123456 | Patterns that cannot handle the (0) convention |
| 0044 7400 123456 | Patterns that only know the plus sign |
| +1 201 555 0123 ext 5 | Patterns that forget extensions |
| +11234567890 | Patterns that allow impossible area codes |
| +4474001234 | Patterns that only count digits |
| +49 30 123456 | Patterns with one fixed length per country |
| 07400 123456 | National formats, valid only once a country is known |
Anchor the pattern with ^ and $, keep quantifiers simple to avoid catastrophic backtracking, and cap the input length before the regex runs. Then compare the false negatives with the false positives and decide which ones you can live with.
Validate for real through the API
The tester proves the point on a few hundred numbers. For production, validation should run where it cannot be skipped:
POST /phoneparses any common format, applies the full metadata and returnsvalid,status, E.164, line type, region, time zones and the original carrier, for 1 credit. The live level adds the current carrier and porting status for 3 credits. See the phone API reference.- For lists, a bulk job runs the same check on up to 2,000,000 rows of a CSV.
- The phone validator and the phone number formatter show the same answers for one number, free.
A free account includes 100 credits a month, and test keys return sample data without spending any, so you can wire the call into your form before going live.
Same check through the API
One HTTPS call, one credit. The response below is the real schema returned by the API.
curl https://api.qelka.com/v1/phone \
-H "Authorization: Bearer sk_test_your_key" \
-H "Content-Type: application/json" \
-d '{"phone":"+12015550123","level":"basic"}'const response = await fetch("https://api.qelka.com/v1/phone", {
method: "POST",
headers: {
Authorization: "Bearer sk_test_your_key",
"Content-Type": "application/json",
},
body: JSON.stringify({
phone: "+12015550123",
level: "basic",
}),
});
const result = await response.json();{
"id": "lkp_01M84QZDVBQCJAMBE4TJB6VRAC",
"object": "phone",
"input": "+12015550123",
"valid": true,
"status": "valid",
"e164": "+12015550123",
"national": "(201) 555-0123",
"country": {
"code": "US",
"name": "United States",
"calling_code": "1"
},
"region": "New Jersey",
"timezones": [
"America/New_York"
],
"line_type": "fixed_line_or_mobile",
"carrier": {
"name": null,
"mcc": null,
"mnc": null,
"source": "numbering_plan"
},
"ported": null,
"credits_used": 1,
"cached": false
}Bulk and pricing
- Upload a CSV of up to 2,000,000 rows from the dashboard or the API, pick the column, get the results back as a CSV.
- Every check costs 1 credit, live phone lookups cost 3. Cached results are billed the same way; calls that fail upstream are not billed.
- The free plan includes 100 credits every month. Paid plans start at $29 for 10,000 credits.
Frequently asked questions
What is the best regex for phone numbers?
What is the regex for an E.164 phone number?
^\+[1-9]\d{1,14}$: a plus sign, a first digit that is not zero, and up to 15 digits in all, the maximum ITU-T E.164 allows. It is a good format gate for data you already normalized. It rejects any number with spaces, and it accepts digit strings no country uses, such as +11234567890 and +999123456789. Run it in the tester to see both.What is the regex for a US phone number?
^(?:\+?1[\s.-]?)?\(?[2-9]\d{2}\)?[\s.-]?[2-9]\d{2}[\s.-]?\d{4}$, accepts the usual ways to write a North American number and enforces the rule that area codes and exchanges start with 2 to 9. It still accepts area codes that do not exist, such as (370) 555-0123, and N11 codes such as (211) 555-0123, which libphonenumber rejects.Why does my regex accept numbers that are not valid?
Why does my regex reject numbers that are valid?
Can a regex check whether a phone number is real?
What do false positive and false negative mean in the tester?
Which regex flavor does the tester use?
\d treats non-ASCII digits. The g and y flags are dropped, because a global RegExp keeps its position between test() calls and would skip matches. Retest in your own language before you ship.How many numbers can I test at once?
Does a UK mobile regex make sure a number is a mobile?
Should I remove spaces and punctuation before matching?
How do I validate phone numbers in an HTML form?
type="tel" for the right mobile keyboard, but note that the HTML standard does not make tel inputs enforce any syntax. A pattern attribute with a loose regex can block obvious typos. Then validate on the server, where the browser cannot skip it: parse with libphonenumber or call the phone API, and store the E.164 form it returns.Can a phone regex slow down my server?
^(\d+)+$, can take exponential time on some inputs that fail to match. OWASP describes this as regular expression denial of service, ReDoS. Keep phone patterns simple, cap the input length before matching, and test a pattern with a long string of digits followed by a letter.How do I find phone numbers inside a block of text?
findPhoneNumbersInText, which uses the metadata to keep only real matches for a default country. For contact details on a website, the website contact finder extracts phone numbers and returns them in E.164.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