cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to make input field accept only numeric values in sapui5 using XML?

former_member195820
Participant
0 Kudos
32,604

Hi all,

I have an input field which should accept only numeric values from the user. I have given its type to be 'Number'. It works fine. But the problem is, it accepts the character 'e'. Is there any other way to validate this?

Here's my code:

<Input id="idlinemgr" width="100%" type="Number" value="" placeholder="Enter here" liveChange="handleLiveChange" />

Can anyone help me with this?

Thanks & Regards,

Ramya

View Entire Topic
former_member227918
Active Contributor

inside liveChange function write below code:

var _oInput = oEvent.getSource();
var val = _oInput.getValue();
val = val.replace(/[^\d]/g, '');
_oInput.setValue(val);

hope this help.

-Akhilesh

former_member644722
Discoverer

Thanks a lot it works fine for me

rami_lgcloud
Explorer
0 Kudos

Thanks, It works great

yash_vijay
Explorer
0 Kudos

Hi,

This solution work great normally but there is a catch, you should not set the input type as Number to validate if using this solution as after adding "e", the value of input would be set as ''.

jacek_wojciechowski
Discoverer
0 Kudos

This solution doesn't prevent an input from accepting non-digits - the character is accepted and then later removed.

For example if you've got the value bound to a model and there's an event registered on the binding or on the model then they will get fired twice.

A better solution is to use an event delegate on keypress.