Last active
February 11, 2021 14:22
-
-
Save Septdir/db3d7b08fc1dc45758ee681731e87a46 to your computer and use it in GitHub Desktop.
Numbers only
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 type="text" numbers-only > | |
<script> | |
document.addEventListener('DOMContentLoaded', function () { | |
document.querySelectorAll('input[numbers-only]').forEach(function (input) { | |
input.addEventListener('input', function () { | |
input.value = input.value.replace(/[^.\d]+/g, '').replace(/^([^.]*\.)|\./g, '$1'); | |
}); | |
}); | |
}); | |
</script> |
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
document.addEventListener('DOMContentLoaded', function () { | |
document.querySelectorAll('input[numbers-only]').forEach(function (input) { | |
input.addEventListener('input', function () { | |
input.value = input.value.replace(/[^.\d]+/g, '').replace(/^([^.]*\.)|\./g, '$1'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment