Requirement
You only want to allow digits 0-9 to be typed in a field
Solution
On the page level, create a function by populating the "execute when page loads" field under the "Javascript" section.
Code
$(".allow-integer").bind("keypress", function (e) {
var keyCode = e.which ? e.which : e.keyCode
if (!(keyCode >= 48 && keyCode <= 57)) {
return false;
}else{
}
});
Now change the CSS Class in the "advanced" section of the field that you want this to apply to, seeting it to the name of the code which we have previously defined in the first step.
Result, now when typing in the field, the field will only recognise key-presses for numberic characters.
NOTE: Users can still paste alphanumeric characters. There are a few dubious posts around explaining how to prevent copy/paste in an apex page. I wasn't convinced that this would work as they forgot about "ctrl-v"!
This was not my requirement though, I was just trying to prevent users from typing silly values.
Acknowledgement
https://www.foxinfotech.in/2020/02/oracle-apex-allow-only-integer-value-using-jquery.html
Comments
Post a Comment