Oracle Apex: Allow Only Integer Value Using jQuery

In this tutorial, I will show you how you can allow only integer value to be entered into a number field in Oracle Apex using the jQuery. Follow these steps:

1. Specify a Class for the Numeric Field

In Oracle Apex, open your page and select the field for which you want to allow only integer values. Then in the Advanced section specify a class allow-integer in CSS Classes field as shown in the below image:

Add a CSS class to a field in Oracle Apex.

2. Add the jQuery Code

Now add the following jQuery code to the Execute when Page Loads section of the page. Below are the code and screenshot for your reference:

 $(".allow-integer").bind("keypress", function (e) {
          var keyCode = e.which ? e.which : e.keyCode               
          if (!(keyCode >= 48 && keyCode <= 57)) {
            return false;
          }else{
          }
      });

Add jQuery code to a Page in Oracle Apex.

Additionally, if you want to specify a particular length of the digits the user can enter, that you can do it by going to the Validation section of the field and specify the maximum length in characters in the input field.

You can specify the same class allow-integer to each field in your page for which you want to allow only integer values.

Now save the changes and run the page to test. It will allow only integer values for that numeric field.

In the next tutorial, I will show you how to allow numbers with a decimal point (Float values) in a field in Oracle Apex using jQuery.

Related tutorials:

Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.

One comment

  1. Thanks. Any idea how you would prevent somebody from pasting "abc" (for example) into this field?

Comments are closed.