1

HTML

<lightning-input type="number" min="0" label="Quantity" ></lightning-input>

So if write something is this and out of the field then it automatically add the comma in between the number and i do not want the comma how i can remove it ?

and yeah if i am using text type instead of number type in lightning input type then comma is not coming but in text field i can write the alphabets and i want only numbers in my field

1 Answer 1

1

Option 1:

Use text type and pattern along with message-when-pattern-mismatch:

<lightning-input pattern="^(0|[1-9][0-9]*)$" 
            message-when-pattern-mismatch="Only numbers can be entered"
            min="0" 
            formatter="decimal"
            label="Quantity" >
    </lightning-input>

Option 2:

Use text type and onchange handler to remove non-number values:

HTML:

<lightning-input 
            min="0" 
            formatter="decimal"
            onchange={handleChange}
            label="Quantity" >
    </lightning-input>

JS:

handleChange(event) {
    let inputVal = event.target.value;
    if(!isFinite(inputVal)) {
        event.target.value = inputVal.toString().slice(0,-1);
    }
}
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.