Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VincentVToscano/f827ef63b9692e8c8e1d3435aa583ca0 to your computer and use it in GitHub Desktop.
Save VincentVToscano/f827ef63b9692e8c8e1d3435aa583ca0 to your computer and use it in GitHub Desktop.
Remove undesired characters for birthday input field
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