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;
}
Comment | File | Size | Author |
---|---|---|---|
#8 | brazilian-1710980-8.patch | 2.49 KB | rfsbsb |
#4 | brazilian-1710980-4.patch | 2.49 KB | rfsbsb |
#2 | brazilian-1710980-2.patch | 2.48 KB | rfsbsb |
Comments
Comment #1
jnl1979 CreditAttribution: jnl1979 commentedComment #2
rfsbsbHere's a patch to solve this.
Comment #3
g1smd CreditAttribution: g1smd commentedIn the above RegEx [ -.]? should be [\s.-]? in several places.
Comment #4
rfsbsbEven though it seems to work with the space instead of \s, I changed it to be more regex compliant.
Comment #5
g1smd CreditAttribution: g1smd commentedHyphen should also be last. Dangerous to not be the last item in the character group.
Comment #6
astutonetThese corrections also must be applied in 7.x. version.
Can anyone help?
Tks
Comment #7
astutonetPerhaps already been solved in http://drupal.org/node/1728142
I will look this. Sorry.
Comment #8
rfsbsbRerolling the patch in order to fit recommendations on regex by @g1smd
Comment #9
rfsbsbSince this is the same implementation for #1728142: New Brazilian phone format which is ok, I committed this one too.