Hello guys, I want to validated in my textbox only numbers shoud be entered and i found this code.

function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;


then i want to validated again only 1 number should be allowed . how to do this? tnx in advance. I mean. When you entered in textbox, only 1 be appeared and then the highest value to entred is 5 greater than five is not allowed. only 1-5. tnx guys.

Edited by peter_budo: Moving to JavaSctip section since it is not relevant to JSP

3 Years
Discussion Span
Last Post by rtrethewey

You don't have to rely on JavaScript for this anymore. Use the HTML 5 <!DOCTYPE html> and you can use:

<input type="number" min="1" max="5" required>

Sorry. I recently used type="range" and I checked caniuse to make sure most current browsers supported it. I didn't notice type="number" wasn't supported by Firefox (which seems odd, but...). As for IE, I figure IE9 and IE10 will disappear quickly, and I've just about given up on IE6-8. I considered mentioning that the target of the form should always validate anyway, along with some cautions about HTML5 support, but I was trying to be brief.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.