maxlength attribute in is not working. Is there any alternative ways for this isuue or any suggestion?

Reffrence: https://developer.salesforce.com/docs/component-library/bundle/lightning:input/example#lightningcomponentdemo:exampleInputNumber

  • can you should me with your code and some screen shot? Oct 15, 2018 at 6:23

3 Answers 3


You could specify a minimum and maximum value. It won't prevent input values outside the range, but will highlight it with a red error message:

<lightning:input label="Some Field" max="9999" min="0" />

Be sure to check validity before saving if you use this technique.

  • Thanks for reply, If I enter decimal value it's fire error, so I used step attribute. But I want to enter value in 3.2(Ex.99.25) format for percent field. Do you have any suggetion for percent field? Oct 15, 2018 at 7:25

I handle through javascript handler, here is code:


<aura:component >
    <lightning:input type="number" aura:id="number" name="input1" 
                     label="Enter a number" maxlength="3" onchange="{!c.CheckLength}"/>

-- Controller.js----

    CheckLength : function(component, event, helper) {
        var val = component.find("number").get('v.value');
        if(val.length > 3){
            var comp = component.find("number");

Its been a while now, but, the lightning:input component now prevents entering additional characters when the set limit has been reached and optionally displays an error message:

<lightning:input maxlength="255" required="true" label="Subject" name="Subject" value="{!v.subjectValue}" messageWhenValueMissing="Complete this field." messageWhenTooShort=" " />

Example (when empty and field is required):

enter image description here

Example (When limit reached): enter image description here

**the char counter is custom, added for visibility purposes.

  • It still doesn't work for number type Apr 25, 2019 at 20:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .