Need a regex pattern to restrict the user to type only a integer ,
I USED the javascript code in the picture i uploaded it had a minor bug ,
and the bug is it takes the first text input but in my case it does not allow even a single text input
kindly suggest me any solution
THANKS IN ADVANCE
Hi,
If you are using querySelectorAll then you need to use below code -
var all = document.querySelectorAll('.mobile'); Array.from({length: all.length}, (v, k) => k).forEach((index) => { let element = all.item(index); element.addEventListener('input', restrictNumber); });
var all = document.querySelectorAll('.mobile'); Array.from({length: all.length}, (v, k) => k).forEach((index) => { let element = all.item(index);
element
.addEventListener('input', restrictNumber); });
function restrictNumber (e) {
var newValue = this.value.replace(new RegExp(/[^0-9\.]/g,'ig'), "");
this.value = newValue;
}
Have a look at this
https://jsmarques13.outsystemscloud.com/RegexHowTo/RegexHowTo
https://www.outsystems.com/forge/component-overview/9512/regex-how-to
And have a look at the demo too where you can see the logic.
Please add below Javascript in your screen "OnRender" event -
var mobile = document.querySelector('.mobile');
mobile.addEventListener('input', restrictNumber);
Thanks
Vinod
I need to do it for almost 10 input widget with same class ,but your code worked only for one input widget in same class so i tried replacing querySelector To querySelectorAll in javascript code it says mobile.addEventListener is not a function
An suggestion .......
Your code is for ES6 so i tried Above code which is in ES5 it works fine
Thanks @Vinod Patidar