0

I need html input which allows only alphanumeric chars. Here is my input

<input type="text" id="l1t1r1c1" onkeypress="javascript:return isAlphaNumeric(event,this.value);" maxlength="5" onkeyup="this.value = minmax(this.value, 0, 99.99, this)">

isAlphaNumeric javascript function works on Chrome but fails in IE 10. How can I run this function in IE10?

here is my function

function isAlphaNumeric(e) { // Alphanumeric only
            var k;
            document.all ? k = e.keycode : k = e.which;
            return ((k > 47 && k < 58) || k == 46 || k == 0);
        };

THX.

neverwinter
  • 810
  • 2
  • 15
  • 42

1 Answers1

2

Syntax error. It is keyCode not keycode

function isAlphaNumeric(e) { // Alphanumeric only
        var k;
        document.all ? k = e.keyCode : k = e.which;
        return ((k > 47 && k < 58) || k == 46 || k == 0);
    }

DEMO

Suresh Ponnukalai
  • 13,820
  • 5
  • 34
  • 54
  • Yeah. your answer fixed my problem. but I am wondering how it worked on Chrome when it has syntax error? :D – neverwinter Jul 14 '14 at 08:03
  • do you know why you have two e.keyCode and e.which?? chrome will take the e.which property. Go through here for more information http://stackoverflow.com/questions/4471582/javascript-keycode-vs-which – Suresh Ponnukalai Jul 14 '14 at 08:05