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!
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
| Component | Description | Matches |
|---|---|---|
^ | Start anchor | Ensures match from string start |
[+]? | Optional plus | Optional + for country code |
[(]? | Optional opening paren | Optional ( character |
[0-9]{3} | First group | Exactly 3 digits |
[)]? | Optional closing paren | Optional ) character |
[-\s.]? | Optional separator | Optional dash, space, or dot |
[0-9]{3} | Second group | Exactly 3 digits |
[-\s.]? | Optional separator | Optional dash, space, or dot |
[0-9]{4,6} | Final group | 4 to 6 digits |
$ | End anchor | Ensures 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-4567555-123-4567555.123.4567555 123 4567(555)123-4567+44 20 7123 45675551234567555-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
- Generic validation: Doesn't validate country-specific formats
- Mismatched parentheses: Allows
(555-123-4567(opening without closing) - No country code validation: Doesn't verify if country code is valid
- Flexible but loose: May accept invalid numbers for specific countries
- 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!