DD
DevDash

Regex for Brazilian Phone Number

Regex Pattern

^(?:\+55)?\d{2}9?\d{8}$

Brazilian phone number with optional +55 country code

Quick Answer

The regex pattern for brazilian phone number is `^(?:\+55)?\d{2}9?\d{8}$`. Brazilian phone number with optional +55 country code. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
+5511987654321✓ Matches
11987654321✓ Matches
+552198765432✓ Matches
+5501234✗ No match
12345✗ No match
+44712345678✗ No match

Code Examples

javascript

const regex = /^(?:\+55)?\d{2}9?\d{8}$/;
const isValid = regex.test(value);

python

import re
pattern = r'^(?:\+55)?\d{2}9?\d{8}$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^(?:\+55)?\d{2}9?\d{8}$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^(?:\+55)?\d{2}9?\d{8}$/', $value)) {
    echo "valid";
}

java

String pattern = "^(?:\\+55)?\\d{2}9?\\d{8}$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.