After reading all of the suggestions, I'd like you to consider a different approach.
Reason
Your code right now disallows user to modify already inserted input in any way with a keyboard. Pressing backspace or delete won't work. Arrows won't work. This does hardly seem as comfortable thing for user.
Suggestion
Consider this example:
var last = '';
var input = document.getElementById('num');
input.addEventListener('input', function(e){
if (isNaN(e.target.value))
e.target.value=last;
else
last=e.target.value;
});
CodePen
Explanation
Hooking to event input will allow you to look at the new value of your input field. You can check, if it is a number (this also includes floats and negative numbers) by using method isNaN, which takes string and returns true if the input is not a number, false otherwise. Therefore, if the condition is true (=not a number), you replace the new value with the last correct one (in this case, default was set to '', but could be something like var last = isNaN(e.target.value)?'':e.target.value;
(for supporting default values or whatever). Otherwise (the input is indeed a number), you leave the value as it is and record it as last successful.
Benefits are obvious, user is allowed to use keys like arrows, backspace, delete or combinations ctrl+c, ctrl+v, while preserving functionality (wrong input (NaN) is immediately deleted).
Note
If you want strictly signed integers, with this approach you can always cut off floating point if you detect it in else clause. Plus, not only isNaN considers . (dot, but not a comma) to be valid part of a number, it also allows notations like 1e3. Check this post for more detail.