javascript icon indicating copy to clipboard operation
javascript copied to clipboard

[feature-request] Add formatPhone

Open linconkusunoki opened this issue 6 years ago • 5 comments

I think it's a good idea to have the ability to format phones (landline and mobile)

as we already have the validators (isValidMobilePhone and isValidLandlinePhone), we could also have the formaters (formatMobilePhone and formatLandlinePhone)

or

just have formatPhone that check if it's mobile or landline and apply the correct mask

linconkusunoki avatar Sep 08 '20 17:09 linconkusunoki

Nice idea @linconkusunoki ! I think these functions fit with our scope and we could have formatPhone, formatMobilePhone and formatLandlinePhone. Would you like to do these functions?

hyanmandian avatar Sep 09 '20 15:09 hyanmandian

Sure! I'll be working on this on the next days 😀

linconkusunoki avatar Sep 10 '20 18:09 linconkusunoki

I was thinking about the functions, and I don't know what is the best approach, because there are cases where we'll need to have the country code, so it'll be something like +55 11 98888-7777. Besides that, we can have the parenthesis on the DDD, so a good function could be:

formatPhone(number, { countryCode: 55, withParenthesis: true })

what do you guys think?

linconkusunoki avatar Sep 16 '20 09:09 linconkusunoki

Nice thoughts @linconkusunoki . I think we can do the simple (but scalable) just receiving a phone number and formatting for the most common format in Brazil (51) 99999-9999. If you think that it should be more customizable, maybe receiving a second parameter (like you said) to remove parenthesis or to add country code (we don't need to change our country code because it always the same) can fit well.

hyanmandian avatar Sep 16 '20 14:09 hyanmandian

Sera coberto na proxima versao!

hyanmandian avatar Jan 29 '25 23:01 hyanmandian