1const source = document.getElementById('source');
2source.addEventListener('input', allowOnlyNumberAndDecimals);
3
4function allowOnlyNumberAndDecimals(e) {
5 let str = e.target.value
6 const regExp = /^(\d+(\.\d+)?)$/
7
8 let status = regExp.test(str) ? 'valid' : 'invalid'
9
10 console.log(status + ' : ' + source.value)
11}