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

Popular posts from this blog

Caps Lock On/Off indicator in Oracle APEX

Change the Column Width of a POPUP LOV Item In Oracle APEX

Display Inline Popup as Callout in Oracle APEX