Last updated: 3 min ago

International Phone Regex Go Example

international phone regex go example for production applications

javascript
advanced
96% accurate
#phone
#validation
#regex
#pattern

Pattern Views

47,489
12.5%Last 30 days

Community Rating

96%
459 likes

Regular Expression

/^\+?1?[-\.\s]?\(?[0-9]{3}\)?[-\.\s]?[0-9]{3}[-\.\s]?[0-9]{4}$/

Explanation

This regex pattern validates international phone regex go example. Commonly used by developers for input validation and form checking.

Code Examples

JavaScript Example
javascript
// international phone regex go example - JavaScript
const regex = /^\+?1?[-\.\s]?\(?[0-9]{3}\)?[-\.\s]?[0-9]{3}[-\.\s]?[0-9]{4}$/;

function validate(input) {
  if (!input || typeof input !== 'string') return false;
  return regex.test(input.trim());
}

// Usage examples
console.log(validate('555-123-4567')); // true
console.log(validate('123')); // false
Python Example
python
# international phone regex go example - Python
import re

pattern = r"^\+?1?[-\.\s]?\(?[0-9]{3}\)?[-\.\s]?[0-9]{3}[-\.\s]?[0-9]{4}$"
regex = re.compile(pattern)

def validate(input_str):
    if not input_str or not isinstance(input_str, str):
        return False
    return bool(regex.match(input_str.strip()))

# Usage examples
print(validate('555-123-4567'))  # True
print(validate('123'))  # False
PHP Example
php
<?php
// international phone regex go example - PHP
function validate($input) {
    if (!is_string($input) || empty(trim($input))) {
        return false;
    }
    
    $pattern = '/^\+?1?[-\.\s]?\(?[0-9]{3}\)?[-\.\s]?[0-9]{3}[-\.\s]?[0-9]{4}$/';
    return preg_match($pattern, trim($input)) === 1;
}

// Usage examples
var_dump(validate('555-123-4567')); // bool(true)
var_dump(validate('123')); // bool(false)
?>

Test Cases

Should Match

555-123-4567
(555) 123-4567

Should NOT Match

123
not-phone