Last active
March 1, 2021 11:17
-
-
Save b-aleksei/2dd11ed5ce9a9152a4d8e0fc34eaf599 to your computer and use it in GitHub Desktop.
DateInputMask
This file contains hidden or 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
input.addEventListener('keypress', function(e) { | |
if(/\D/.test(e.key)) { | |
e.preventDefault(); | |
} | |
const len = input.value.length; | |
if(len === 1 || len === 4) { | |
setTimeout(() => { | |
input.value += '/'; | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment