How can I modify a regular expression to validate additional phone number formats using JavaScript?

I found a regular expression that works well for validating phone numbers in the following formats:

  • (123) 456-7890
  • 123-456-7890

The issue is that my client wants to allow a third format where the phone number is written as 1234567890, with no spaces or special characters.

Here’s the regular expression I’m currently using:

/^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/

How can I modify this to also validate the format where the phone number consists of ten consecutive digits like 1234567890? I’m not very experienced with regular expressions, so any guidance would be appreciated!

I’ve handled a few similar cases before, and when it comes to javascript validate phone number patterns, it’s actually not too hard to adjust. To support numbers without any separators, you can expand your regular expression slightly.

Here’s a refined solution:

/^\(?\d{3}\)?[-\s]?\d{3}[-\s]?\d{4}$|^\d{10}$/

Quick breakdown: We’re using the | (OR) operator to allow two patterns:

  • The first matches your original formats (with parentheses, spaces, or dashes).
  • The second ^\d{10}$ cleanly allows exactly ten digits without any formatting.

This should now cover all three formats your client wants!

I’ve worked on a few projects where we needed even more flexibility while doing javascript validate phone number checks. One way to make it even smoother is by slightly tweaking how we match unformatted numbers.

You could use this pattern:

/^\(?\d{3}\)?[-\s]?\d{3}[-\s]?\d{4}$|^\d{3}\d{3}\d{4}$/

Why this version?

It keeps supporting the usual formatted numbers, but it treats the 10 consecutive digits as three groups (3-3-4 digits) internally. It’s functionally similar to the first answer but a bit cleaner under the hood for the javascript validate phone number process — especially if you want to extend it later (e.g., to handle extensions).

Based on my experience doing javascript validate phone number implementations for apps that had messy user input, it’s smart to anticipate slight variations.

Here’s an even more flexible version:

/^\(?\d{3}\)?[-\s]?\d{3}[-\s]?\d{4}$|^\d{10}$|^\d{3}[-\s]?\d{3}[-\s]?\d{4}$/

What’s new here? This not only allows clean (123) 456-7890, 123-456-7890, and 1234567890, but it also accepts slight mixes — like numbers separated by just spaces or just hyphens — without breaking validation. It’s a bit more forgiving, making your javascript validate phone number feature feel much smarter and user-friendly.