Qaynaq LABS · TOOLS

REGEX · JAVASCRIPT

Regex explained

^\+?[0-9]{10,15}$

Matches a string that starts with an optional plus sign followed by 10 to 15 digits, with no other characters before or after.

Token-by-token breakdown

TokenMeaningExample
^ Anchor: asserts position at start of the string +1234567890
\+ Escaped plus sign: matches a literal '+' character +1234567890
? Quantifier: matches the preceding token (\+) zero or one time (i.e., optional) 1234567890
[0-9] Character class: matches any single digit (0-9) 1
{10,15} Quantifier: matches the preceding token ([0-9]) between 10 and 15 times (inclusive) 1234567890
$ Anchor: asserts position at end of the string +123456789012345

Matches

  • 1234567890
  • 12345678901
  • +1234567890
  • +123456789012345

Does not match

  • +123456789
  • 1234567890123456
  • abc1234567890
  • 1234567890+
  • 123-456-7890

Common pitfalls

  • Forgetting to escape the '+' character, which in regex has a special meaning (one or more of the preceding token).
  • Assuming the pattern matches international phone numbers with country codes (e.g., '+1-555-123-4567').
  • Not accounting for strings with leading or trailing whitespace (anchors ^ and $ do not ignore whitespace).

Performance notes

The pattern is efficient with no catastrophic backtracking risk. Anchors (^ and $) ensure the entire string is evaluated, which is optimal for this use case.

About regular expressions

Regular expressions are tiny programs that match patterns in text. They're powerful and notoriously cryptic — most engineers can write them but few can read them confidently. Qaynaq Labs' regex explainer breaks any pattern into its constituent tokens, shows what each one does, and runs through both matching and non-matching examples so you can verify the logic.

Different regex flavors (JavaScript, PCRE, Python, Go) have subtle differences in syntax and supported features. Pick your flavor in the input — the explainer accounts for it.

Frequently asked

Does this pattern match phone numbers with spaces or hyphens?

No, the pattern only matches digits and an optional leading plus sign. Spaces or hyphens would cause the match to fail.

Can this pattern match a string with fewer than 10 digits?

No, the quantifier {10,15} requires at least 10 digits.

Is this pattern suitable for validating international phone numbers?

No, international phone numbers often include country codes, area codes, and formatting characters, which this pattern does not account for.