Oracle Apex: Allow Only Integer Value Using jQuery

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:

This Post Has One Comment

  1. Barry Brierley

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

Comments are closed.