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;
}

Comments

Assigned:jnl1979» Unassigned

Status:Active» Needs review
StatusFileSize
new2.48 KB

Here's a patch to solve this.

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

StatusFileSize
new2.49 KB

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

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

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

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

Can anyone help?

Tks

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

Perhaps already been solved in http://drupal.org/node/1728142

I will look this. Sorry.

StatusFileSize
new2.49 KB

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

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.