Last active
April 6, 2020 10:31
-
-
Save AirStair/70ad2da5ba4f4e3e7b485c5e2dc138a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const phoneMask = selector => { | |
const phoneElement = document.querySelector(selector); | |
phoneElement.addEventListener('keyup', () => { | |
const match = phoneElement.value.replace(/\D+/g, '').match(/(\d{1})(\d{3})(\d{3})(\d{2})(\d{2})/); | |
phoneElement.value = `${match[1]} (${match[2]}) ${match[3]}-${match[4]}-${match[4]}`; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment