Well, I think there are mixed concepts and some errors in the example of both html and jquery, so I've edited it. Still, literally following your instructions.
function mostrar() {
var x = $("#numero").val();
alert(x);
}
<input type="number" step="1" onkeyup="mostrar()" id="numero" size="20"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
It's annoying, does not it? you could indicate if you need some timeout or wait for a specific event to occur such as onBlur, onChange ...
** Update **
your example being the following:
function mostrar(num) {
var x = $("#num").val();
alert(x);
}
<input type="text" name="num" step="1" Onchange = "mostrar('num')" value="" size="20"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
there are still errors in your code, even so:
function mostrar(input) {
//solo queremos mostrar la alerta
// si tengo un formato en concreto
// por ejemplo dos numeros separados por un espacio
if(/[0-9]+ [0-9]+/.test(input.value)){
var numeros = input.value.split(' ');
alert(numeros[0]+','+numeros[1]);
}
//o con jquery usando this
if(/[0-9]+ [0-9]+/.test($(input).val())){
var numeros = $(input).val().split(' ');
alert(numeros[0]+','+numeros[1]);
}
}
<p>
onchange se ejecuta al perder el focus o al cambiar de valor solo en campos select, radio y checkbox <br>
<input type="text" onchange="mostrar(this)"/>
</p>
<p>
onkeyup se ejecuta justo despues de cada introduccion o eliminacion de caracteres <br>
<input type="text" onkeyup="mostrar(this)"/>
</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>