Skip to Content
avatar image
Former Member

How to restrict input control to certain length when type is number?

maxlength property is not working

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    May 31, 2017 at 07:34 AM

    Hi

    This works fine,

    View.xml

    <Input id="inputId" maxLength="5">

    Controller.js

    this.getView().byId("inputId").attachBrowserEvent("keypress",function(e){

    var mphone_code=[48,49,50,51,52,53,54,55,56,57,32];
    if(!($.inArray(e.which,mphone_code)>=0)){
    e.preventDefault();
    }
    })

    Regards,

    Chethan RK

    Add comment
    10|10000 characters needed characters exceeded