I am trying this below code and the regex isn't working and it is allowing all the characters in the input box.
Desired: Input text box should not accept any other character other than numbers and decimal point.
<html>
<body>
<input type="text" onkeypress="myfunction(event);"></input>
<script>
function myfunction(e){
var p = new RegExp(/^[0-9]+([.][0-9]+)?$/);
return e.charCode === 0 || p.test(String.fromCharCode(e.charCode));
}
</script>
</body>
</html>