Back to Home

General Phone Number Validation Regex (Generic Strict)

CronOS Team
regexphonevalidationtutorialgeneral

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern

General Phone Number Validation Regex (Generic Strict)

A generic strict regex pattern for validating phone numbers with optional country code, parentheses, and flexible formatting.

Pattern Breakdown

regex
^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$

Components

ComponentDescriptionMatches
^Start anchorEnsures match from string start
[+]?Optional plusOptional + for country code
[(]?Optional opening parenOptional ( character
[0-9]{3}First groupExactly 3 digits
[)]?Optional closing parenOptional ) character
[-\s.]?Optional separatorOptional dash, space, or dot
[0-9]{3}Second groupExactly 3 digits
[-\s.]?Optional separatorOptional dash, space, or dot
[0-9]{4,6}Final group4 to 6 digits
$End anchorEnsures match to string end

Character Classes

  • [+]? - Optional plus sign for international format
  • [(]? - Optional opening parenthesis
  • [0-9]{3} - Exactly 3 digits
  • [)]? - Optional closing parenthesis
  • [-\s.]? - Optional separator: dash, space, or dot
  • [0-9]{4,6} - Between 4 and 6 digits (flexible length)

Examples

Valid:

  • +1 (555) 123-4567
  • 555-123-4567
  • 555.123.4567
  • 555 123 4567
  • (555)123-4567
  • +44 20 7123 4567
  • 5551234567
  • 555-123-45678 (6 digits in last group)

Invalid:

  • 555-123-456 (last group too short, needs 4-6 digits)
  • 55-123-4567 (first group too short)
  • 555-12-4567 (second group too short)
  • 555-123-4567890 (last group too long)
  • 555@123-4567 (invalid separator)

Implementation

JavaScript

javascript
const phoneRegex = /^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/;
phoneRegex.test('+1 (555) 123-4567'); // true
phoneRegex.test('555-123-4567'); // true
phoneRegex.test('555.123.4567'); // true
phoneRegex.test('555-123-456'); // false (last group too short)

Python

python
import re
phone_regex = r'^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$'
bool(re.match(phone_regex, '+1 (555) 123-4567'))  # True
bool(re.match(phone_regex, '555-123-4567'))  # True
bool(re.match(phone_regex, '555-123-456'))  # False (too short)

Go

go
phoneRegex := regexp.MustCompile(`^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$`)
phoneRegex.MatchString("+1 (555) 123-4567") // true
phoneRegex.MatchString("555-123-4567") // true
phoneRegex.MatchString("555-123-456") // false (too short)

Limitations

  1. Generic validation: Doesn't validate country-specific formats
  2. Mismatched parentheses: Allows (555-123-4567 (opening without closing)
  3. No country code validation: Doesn't verify if country code is valid
  4. Flexible but loose: May accept invalid numbers for specific countries
  5. Mixed separators: Allows mixed formats which may be undesirable

When to Use

  • General phone number input forms
  • When you need to accept various international formats
  • Quick format checking across multiple countries
  • When exact country validation isn't critical
  • Prototyping or early development

For production, consider:

  • Country-specific validation patterns
  • Using phone number validation libraries
  • Normalizing phone numbers before storage
  • Validating country codes
  • Server-side validation

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern