0

How do I ensure that the user only types numbers in lightning: input?

Currently tried with pattern but to no avail:

<lightning:input type="text" label="Numeric value" aura:id="myInput" name="myInput" pattern="[0-9]"/>

enter image description here

Also, I would like to format this field to a decimal with one place after the comma.

For that I already used the "step = 0.1" but also to no avail.

1
  • why are you not using a number type component as mentioned bellow by sfdcfox?
    – glls
    Jul 31, 2019 at 2:03

1 Answer 1

1

Use the "number" type instead:

<lightning:input type="number" step="0.1" ... />

The "text" type is not suitable for your purpose.

2
  • i need use "input" instead of "lightning input"? Jul 30, 2019 at 22:03
  • @DiegoEdargoPessoa whoops m no, that was a typo. I'll edit.
    – sfdcfox
    Jul 30, 2019 at 22:37

You must log in to answer this question.

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