Javascript allow only numbers and decimals

Check enter value is number or not

function isNumber(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    console.log(charCode)
    if (charCode == 45 || charCode == 46) {
        return true;
    } else if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}
DEMO
Javascript allow only numbers and decimals Javascript allow only numbers and decimals Reviewed by Bhaumik Patel on 7:43 PM Rating: 5