Q: Trigger function on number input I have a text input where users are able to write addresses, I want to trigger a javascript function when a number is typed in the text input, how can I achieve it?
EDIT: What I need is to know when a number has been typed, onkeyup via jquery works like a charm, this is what I did:
$("#q").keyup((e) => {

        var value = $("#q").val();

        var regex = new RegExp("[a-zA-Z0-9_ ]\\d+");

        var succeded = regex.test(value);

        ...


A: You can simply do:
$("input").keyup(function(){
    $("input").css("background-color", "pink");
});

Source

A: you just need to use build in KeyEvents, like (keyDown, keyUp, keyPress , etc.).
You can find a lot of information about it.
KeyboardEvent mozilla


*

*Create html input, and give unique ID.

*Form JS code take this element.

*Then just bind event handler to target element.
["YOUR_ELEMENT"].addEventListener("keypress", function(e) {
console.log(e.value);}, false);

A: $('.js-input').on('keydown', function(e) {
    console.log('pressing:', e.keyCode);
});

<input type="text" class="js-input">

DEMO
This will get you started

A: This will do your job:
$('#tbInput').keypress(function(event){

if(event.which != 8 && isNaN(String.fromCharCode(event.which))){
}
else
{
//Your function that you want to trigger.
alert("You pressed a numberic key: " + event.which);
}});

You can test it here:
JSFIDDLE DEMO
