admin管理员组文章数量:1402188
I have an item in a form which is a number field and I want to somehow make sure that only numbers are accepted in the field. If users enter letters I want the field to reject it.
I already tried a validation but it was unsuccessful, is there anyway I get make this happen via a dynamic action with either a javascript code or a "pl/sql code"?
I have an item in a form which is a number field and I want to somehow make sure that only numbers are accepted in the field. If users enter letters I want the field to reject it.
I already tried a validation but it was unsuccessful, is there anyway I get make this happen via a dynamic action with either a javascript code or a "pl/sql code"?
Share Improve this question edited Sep 28, 2020 at 19:37 Littlefoot 143k15 gold badges40 silver badges63 bronze badges asked Sep 28, 2020 at 19:00 ChepeChepe 771 silver badge11 bronze badges5 Answers
Reset to default 3There's absolutely nothing you should do except setting its type to Number field.
Yes, you can type anything you want into it, but Oracle won't store anything but numbers. It'll raise the "Field name must be numeric" error and stop.
Why would you want to reinvent the wheel?
If you must, try with dynamic action on that item (let's call it P13_DEPTNO)
.
When event: Key Press
Selection type: Item
Item: P13_DEPTNO
True action: execute PL/SQL code (with "Items to submit": P13_DEPTNO):
begin if not regexp_like(:P13_DEPTNO, '^\d+$') then raise_application_error(-20000, 'Digits only'); end if; end;
In case anyone needs the answer....
enter this in the page JAVASCRIPT and GLOBAL variable declaration....
function setInputFilter(textbox, inputFilter) {
["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function(event) {
textbox.addEventListener(event, function() {
if (inputFilter(this.value)) {
this.oldValue = this.value;
this.oldSelectionStart = this.selectionStart;
this.oldSelectionEnd = this.selectionEnd;
} else if (this.hasOwnProperty("oldValue")) {
this.value = this.oldValue;
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
} else {
this.value = "";
}
});
});
}
Then go to the page item you want to restrict to numbers, and right click, add dynamic action, when: event: key press, selection type: items, items (item you have selected), add a true action...and have it execute JS CODE, then enter this code... replace the page item with your page item name...
setInputFilter(document.getElementById("PXX_XXXX"), function(value) {
return /^-?\d*$/.test(value); });
And it will only let you enter numbers into the item.
you can solve this by using a bination of oninput and pattern matching to ensure only numeric input:
<input type="text" id="numericInput" name="numericInput" oninput="this.value=this.value.replace(/[^0-9]/g,'');">
So, put oninput="this.value=this.value.replace(/[^0-9]/g,'');"
into Advance --> Custom Attributes of the item.
Done!!
Sometimes you do need to prevent users from inserting anything else but numbers. Especially if this field is used for calculations. So you can use this https://www.foxinfotech.in/2020/02/oracle-apex-allow-only-integer-value-using-jquery.html
I have created a blog post for this usecase. Please refer the below link
https://akilramesh.blogspot./2021/10/allow-only-numbersdecimal-in-numbertext.html
版权声明:本文标题:javascript - Oracle Apex: How can I restrict a numeric field in a form to allow numbers only? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744268824a2598079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论