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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.