Allow Only Number/Decimal values In a Number/Text Field Using JavaScript in Oracle APEX



In this blog I will be explaining how to restrict users from typing only numbers/decimal values in a Number/Text Item in Oracle APEX.

1) Create a Region.
  
2) Create an Item in the page (Type: Text Field or Number Field).

3) To allow only Numbers, paste the below code in the Page -> Execute When Page Loads Section.
$("#P30_NUMBER_FIELD_ITEM").keypress(function(event){ 
    event = (event) ? event : window.event;
    var charCode = (event.which) ? event.which : event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
       return false;
    }
    return true;
});
  •  Note: Replace P30_NUMBER_FIELD_ITEM with your Item name.

4) To allow only Decimal values, paste the below code in the Page -> Execute When Page Loads Section.
$("#P30_DECIMAL_FIELD_ITEM").keypress(function(event){ 
    event = (event) ? event : window.event;
    if ( event.which != 0 && (event.which < 48 || event.which > 57) && (event.which != 46 || $(this).val().indexOf('.') != -1)){    
       return false;
    }
    return true;
});
  •  Note: Replace P30_DECIMAL_FIELD_ITEM with your Item name.



Please click here for DEMO

Happy CODING !!!

Thank you :)

Comments

  1. How to reduce decimal number

    ReplyDelete
  2. congnaFmelba Paula Evans click
    pilinunfrock

    ReplyDelete
  3. Hey man... thanks for sharing, I really appreciate! :-)

    ReplyDelete

Post a Comment

Popular posts from this blog

Display and Edit CLOB Content in Oracle APEX

Copy the value of an Item to Clipboard in Oracle APEX