Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brazilian format is wrong #21

Closed
CavalcanteLeo opened this issue Mar 23, 2018 · 8 comments
Closed

Brazilian format is wrong #21

CavalcanteLeo opened this issue Mar 23, 2018 · 8 comments

Comments

@CavalcanteLeo
Copy link

CavalcanteLeo commented Mar 23, 2018

We have 2 patterns:

+55 (XX) XXXXX-XXXX
and
+55 (XX) XXXX-XXXX

country code
state code (2 digits)
4 or 5 digits, then 4 digits

It depends on which state the number is

@NikKovIos
Copy link
Owner

Thanks for your issue. Now it's not available to set multiple formats (
Gonna look what can do there...

@NikKovIos
Copy link
Owner

Imagine the user type +55 than any digits. How the app should be available to distinguish between two patterns? Are there any characteristics which inherent to one and another pattern? Maybe unique digit sequence of concrete numbers?

@CavalcanteLeo
Copy link
Author

CavalcanteLeo commented Jun 8, 2018

this might be a good help
http://pedroelsner.com/2012/07/mascara-jquery-para-novo-digito-de-celular-em-sao-paulo/

also this one:

https://gist.github.com/MauricioMoraes/2885d4975ac5e52d0ad7

all of those are using question mark "?" in the mask, maybe some regex detect it

The input will change the mask as the user types

@NikKovIos
Copy link
Owner

So, according the second code, is it would be correct if mask would apply only when the last character typed? Cos this code apply the mask depending on phone length. If 9 characters it's one pattern. If 10, than the other.

@CavalcanteLeo
Copy link
Author

yep, it changes the mask when the last character is typed, also it change where the hyphen "-" is

I think i've done a long time ago a mask for this case using objective-c as well, i will try to find it tomorrow. Dunno if i still have the code.

@CavalcanteLeo
Copy link
Author

CavalcanteLeo commented Jun 8, 2018

Found a solution:

https://github.com/Serheo/SHSPhoneComponent

It adds more than 1 pattern, just loop through the patterns and add setDefaultOutputPattern

//patter 1
[self.phoneField.formatter setDefaultOutputPattern:@"##########" imagePath:nil]; 
//patter 2
[self.phoneField.formatter addOutputPattern:@"+# (###) ###-##-##" forRegExp:@"^7[0-689]\\d*$" imagePath:@"flagRU"]; 
//patter 3
[self.phoneField.formatter addOutputPattern:@"+### (##) ###-###" forRegExp:@"^374\\d*$" imagePath:@"flagAM"];

but, the regex must match the brazilian digits (9 or 10 digits)

@NikKovIos
Copy link
Owner

Thanks🙆, ill watch this closely in a free time.

@NikKovIos
Copy link
Owner

Further discussion there: #33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants