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

Replacing first 8 to +7 #408

Closed
AeShevch opened this issue Oct 26, 2020 · 2 comments
Closed

Replacing first 8 to +7 #408

AeShevch opened this issue Oct 26, 2020 · 2 comments

Comments

@AeShevch
Copy link

AeShevch commented Oct 26, 2020

Greetings!
I need that if the user enters 8 as the first digit, it is replaced with"+7".
That is, I need not only the first 7 to turn into +7, but the first 8 to turn into +7 as well.
Is it possible to do this?
+7(8##)###-##-## => +7(###)###-##-##

var maskOptions = {
  mask: '+{7}(000)000-00-00'
};
var mask = IMask(element, maskOptions);```

@AeShevch
Copy link
Author

AeShevch commented Oct 26, 2020

Solution:

const phoneInput = document.querySelector(`.js-phone-input`);
   IMask(phoneInput, {
                        mask: '+{7} (000) 000 0000',
                        prepare: (appended, masked) => {
                          if (appended === '8' && masked.value === '') {
                            return '';
                          }
                          return appended;
                        },
                      });
                   

@uNmAnNeR
Copy link
Owner

uNmAnNeR commented Feb 9, 2021

thanks!

@uNmAnNeR uNmAnNeR closed this as completed Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants