Cyberlicious
Cyberlicious

Reputation: 49

How to Include space on number input?

How to include the spaces (not text, only spaces and numbers) on the input type? When i try my code it only includes numbers

This is my code:

<form action="/action_page.php"><input type="number"/><input type="submit"</form>

Upvotes: 2

Views: 11406

Answers (3)

user369662
user369662

Reputation: 1

This option is perfect for me.

<input type = "text" inputmode = "numeric">
input.addEventListener("input", inputEvent => {
    input.value = input.value.replaceAll(/\D/g, "");
    
    if (inputEvent.inputType === "insertText"){
        input.value = new Intl.NumberFormat().format(value);
    }
}

Upvotes: 0

Nicolas Hedoire
Nicolas Hedoire

Reputation: 83

You need to use type="text" for your input in order to format your value as you want. type="number" does not work with this kind of format.

const formatter = new Intl.NumberFormat('fr-FR');

<input
  type="text"
  value={formatter.format(value)}
/>

Upvotes: 1

priyadarshini puja
priyadarshini puja

Reputation: 139

<form action="/action_page.php">
    <input type="text" pattern="[0-9 ]+" />
    <input type="submit"</form>

you can use input with type text and add pattern "[0-9 ]+".

Upvotes: 1

Related Questions