no only fields 2

by Fernando De Leon

HTML

<input type="text" id="fname" onkeyup="myFunction()">

JavaScript

function myFunction() {
    var x = document.getElementById("fname");
    //for only digits
   //x.value = x.value.replace(/[1-9()]/g,'match');
    //for only digits and ()
    //x.value = x.value.replace(/[^0-9^(^)]/g,'');
    //for only digits and () and whitespace
    x.value = x.value.replace(/[^0-9^(^)^\s]/g,'');
    //x.value = x.value.replace(/\D/g,'');
   // x.value = x.value.replace(/\D\^(\^)\-/g,'');
   
}