Created
July 27, 2023 17:39
-
-
Save VincentVToscano/f827ef63b9692e8c8e1d3435aa583ca0 to your computer and use it in GitHub Desktop.
Remove undesired characters for birthday input field
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
const birthday_input = document.querySelector("#birthnumber"); | |
const BIRTHNUMBER_ALLOWED_CHARS_REGEXP = /[A-Za-z0-9_-]+/; | |
birthday_input.addEventListener("beforeinput", e => { | |
if (!BIRTHNUMBER_ALLOWED_CHARS_REGEXP.test(e.data)) { | |
e.preventDefault(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment