[Solved] Check with Javascript if a textarea value is numeric [closed]


HTML:

<textarea id="text"></textarea>​

JavaScript:

var re=/\d/,
    allowedCodes = [37, 39, 8, 9], // left and right arrows, backspace and tab
    text = document.getElementById('text');

text.onkeydown = function(e) {
    var code;
    if(window.event) { // IE8 and earlier
        code = e.keyCode;
    } else if(e.which) { // IE9/Firefox/Chrome/Opera/Safari
        code = e.which;
    }
    if(allowedCodes.indexOf(code) > -1) {
        return true;
    }
    return !e.shiftKey && re.test(String.fromCharCode(code));
};​

Demo

solved Check with Javascript if a textarea value is numeric [closed]