I have for the following input:
onkeyup="this.value = this.value.replace (/\D/, '')" How to make, in addition to numbers it was possible to enter also the + sign?
I have for the following input:
onkeyup="this.value = this.value.replace (/\D/, '')" How to make, in addition to numbers it was possible to enter also the + sign?
onkeyup="this.value = this.value.replace (/[^0-9+]/, '')" ттттт key, or through CTRL+V You need to add the modifier g - onkeyup="this.value = this.value.replace (/[^0-9+]/g, '')" - Maxim BelovAs an option.
Disadvantage: any characters can be entered via CTRL+V
function cislo(){ if (event.keyCode != 43 && event.keyCode < 48 || event.keyCode > 57) event.preventDefault(); } <input type="text" onKeyPress="cislo()"> Another option - the characters can not be entered even through CTRL+V
document.oninput = function() { var input = document.querySelector('.input-0'); input.value = input.value.replace (/[^\+\d]/g, ''); } <input type="text" class="input-0"> 123 /&*-+"! . - 0xdbSource: https://ru.stackoverflow.com/questions/259545/
All Articles