use Javascript "Onkeypress" command to accept only "numeric". - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

use Javascript "Onkeypress" command to accept only "numeric".

Good day. Is there a way to filter typed inputs right upon typing the characters using Javascript? i plan on using Javascript's "Onkeypress" command to accept only "numeric, i.e., 1,2,3...", ". (dot)", and ", (comma)" command. please help.thanks in advance.

Comments

  • BijuRajBijuRaj Posts: 5Member
    : Good day. Is there a way to filter typed inputs right upon typing the characters using Javascript? i plan on using Javascript's "Onkeypress" command to accept only "numeric, i.e., 1,2,3...", ". (dot)", and ", (comma)" command. please help.thanks in advance.
    :

    =================================================
    Here is your solution
    =================================================

    57 || event.keyCode==45 || event.keyCode==47) event.returnValue = false;">


  • elizaselizas Posts: 15Member
    Basicallly When we trying to validate a form some time we need numeric validation for textbox.

    We can validate textbox by onkeypress event of the control By checking whether the keycode of the key pressed as the user types falls within the range of the number keys 48-57(i.e 0-9 and '.') ,if not belong to that range it will return false then it will disable the keypress action
    function NumericValidation(eventObj)
    {
    var keycode;

    if(eventObj.keyCode) //For IE
    keycode = eventObj.keyCode;
    else if(eventObj.Which)
    keycode = eventObj.Which; // For FireFox
    else
    keycode = eventObj.charCode; // Other Browser

    [code]http://www.mindfiresolutions.com/Numeric-validation-using-Javascript-612.php[/code]
Sign In or Register to comment.