As the regular season do not allow to enter 0 only the first character?

and the second, third, and so on - can
now 0 do not enter

restrictions on entering characters leave
https://jsfiddle.net/zdLx5yh6/
April 19th 20 at 12:38
2 answers
April 19th 20 at 12:40
Solution
Jquery:

$('input').on('input', function() {
 this.value = this.value.replace(/^0|[^\d]/g, ");
})


Vanilla JS:

const input = document.querySelector(".input");

input.addEventListener("input", (event) => {
 event.target.value = event.target.value.replace(/^0|[^\d]/g, ");
});
@Franz_Blan , please explain the regular season

if it starts with 0 or begins with any numeric character, replaced by "
But why replace only 0 ? - Julio.Erdma commented on April 19th 20 at 12:43
@Julio.Erdma, I'm not really a master in explaining such things as regexps rarely work. - Franz_Blan commented on April 19th 20 at 12:46
@Julio.Erdma, [^\d] is "netira". I.e., this expression will kill characters, spaces, etc. - hellen5 commented on April 19th 20 at 12:49
@hellen5, right, thanks - Julio.Erdma commented on April 19th 20 at 12:52
April 19th 20 at 12:42
Solution
/^0|\D/g
@ursula_Fah, and how does it work?
because ^ banned only the first character is 0? - Lizeth_Kling53 commented on April 19th 20 at 12:45
@Lizeth_Kling53Literally stands for zero in the beginning of the line (^) or (|) not a digit (\D). - ursula_Fah commented on April 19th 20 at 12:48

Find more questions by tags Regular expressionsJavaScript