Skip to Content

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Aug 29, 2018 at 05:35 PM
    -1

    Hi

    You can try this without needing to program and to check it.

    <Input type="Number"
    
    	placeholder="Enter Number please....."
    
    	fieldWidth="25%"description="Units"
    
    	liveChange="onChange">
    
    </Input>

    Regards

    Ebrahim

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20, 2017 at 01:24 PM

    Hi,

    This is the expected behaviour so that the user can enter something like 1e5 instead of 100000 for instance. You should probably not change this but if you really want to do it, you can use jQuery to achieve this: http://stackoverflow.com/questions/995183/how-to-allow-only-numeric-0-9-in-html-inputbox-using-jquery/995193#995193

    Cheers,

    Pierre

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 20, 2017 at 01:28 PM

    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

    Add comment
    10|10000 characters needed characters exceeded