Simple input constraint

The construction written below can restrict the input of certain characters in the input field on the form. The main advantage is simplicity. The main disadvantage is that you can insert a letter through ctrl+V

<input type="text" onKeyUp="this.value = this.value.replace (/\D/, '')">
  1. How to disable pasting via ctrl+v?
  2. How not to restrict input, but make only certain characters available? Say only numbers, or only letters, or numbers+letters+punctuation?

if ( if anyone answers ) { thanks in advance }

Answer 1, authority 100%

  1. Replace /\D/with /\D/g– will remove all letters, not just one.
  2. Only your way + similar validation on the server side.

Answer 2, authority 100%

The idea is correct, but firstly, it is not quite right to put such things on keyUp in relation to the user – letters will appear and disappear for him – and secondly, with such a construction you do not forbid something to be entered, but only modify it already entered value.

My version (for entering only numbers) – copes with ctrl+V =)

//   //
function chk_int_value(event)
    var list=new Array (8,48,49,50,51,52,53,54,55,56,57,58,96,97,98,99,100,101,102,103,104,105,106);
    var i;
            return true;    
    return false;
    return chk_int_value(event);