This week the phone company has added an extra number some phone numbers.

Before (11) 1111 - 1111

Today (11) 11111 - 1111 or (11) 1111 - 1111

Today the validator only allows me to do the before method. Can someone help me with this issue?
I believe that i have to change this but don´t know how.

define('PHONE_BR_REGEX', "/^(\+|0{2}|)?(55|0|)[ -.]?((\(0?[1-9][0-9]\))|(0?[1-9][0-9]))[ -.]?([1-9][0-9]{2,3})[ -.]?([0-9]{4})$/");

and maybe something over here?

function format_br_phone_number($phonenumber, $field = FALSE) {
$phone = str_replace(array(' ','-','(',')'), '', $phonenumber);
if (preg_match(PHONE_BR_REGEX, $phone, $matches) != 1) {
return $phonenumber; // this is possible?
$formatedphone = '';
if ($field && $field['phone_country_code']) {
$formatedphone .= '+55 ';
$formatedphone .= '(' . $matches[3] . ')';
$formatedphone .= ' ' . $matches[6] . '-';
$formatedphone .= '' . $matches[7];

return $formatedphone;

Members fund testing for the Drupal project. Drupal Association Learn more


jnl1979’s picture

Assigned: jnl1979 » Unassigned
rfsbsb’s picture

Status: Active » Needs review
2.48 KB

Here's a patch to solve this.

g1smd’s picture

In the above RegEx [ -.]? should be [\s.-]? in several places.

rfsbsb’s picture

2.49 KB

Even though it seems to work with the space instead of \s, I changed it to be more regex compliant.

g1smd’s picture

Hyphen should also be last. Dangerous to not be the last item in the character group.

astutonet’s picture

Version: 6.x-2.18 » 7.x-1.x-dev

These corrections also must be applied in 7.x. version.

Can anyone help?


astutonet’s picture

Version: 7.x-1.x-dev » 6.x-2.18

Perhaps already been solved in

I will look this. Sorry.

rfsbsb’s picture

2.49 KB

Rerolling the patch in order to fit recommendations on regex by @g1smd

rfsbsb’s picture

Status: Needs review » Fixed

Since this is the same implementation for #1728142: New Brazilian phone format which is ok, I committed this one too.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.