# How can I specify \<input type="number"\> with only integer

**URL:** <https://forums.creativeclouddeveloper.com/t/how-can-i-specify-input-type-number-with-only-integer/4904>\
**Category:** UXP Plugin API\
**Created:** [July 5, 2022, 4:03pm UTC](https://forums.creativeclouddeveloper.com/t/how-can-i-specify-input-type-number-with-only-integer/4904 "2022-07-05T16:03:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![karpiyon](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@karpiyon](https://forums.creativeclouddeveloper.com/u/karpiyon)\
**Post date:** [July 5, 2022, 4:03pm UTC](https://forums.creativeclouddeveloper.com/t/how-can-i-specify-input-type-number-with-only-integer/4904/1 "2022-07-05T16:03:24Z")

</div>

Hi,  
Is there more control on teh input data type for numbers when using spectrum?  
E.g. only integers, or limit the number of digits?

---

<div class="post-metadata">

**Author:** ![bbogdan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/bbogdan/32/2272_2.png) [@bbogdan](https://forums.creativeclouddeveloper.com/u/bbogdan)\
**Post date:** [July 9, 2022, 7:28pm UTC](https://forums.creativeclouddeveloper.com/t/how-can-i-specify-input-type-number-with-only-integer/4904/3 "2022-07-09T19:28:48Z")

</div>

Probably the solution is to use regex and react to achieve this. Look at the following code:

```auto
import { useState } from "react";

export default function App() {
  const [inputValue, setInputValue] = useState("");

  const keepInRange = (currentValue, min, max) => {
    const value = parseInt(currentValue.replace(/\D/g, ""));
    if (isNaN(value)) {
      return "";
    } else if (value < min) {
      return min.toString();
    } else if (value > max) {
      return max.toString();
    } else {
      return value.toString();
    }
  };

  const handleChange = (event) => {
    setInputValue(keepInRange(event.currentTarget.value, 1, 100));
  };

  return (
    <div className="App">
      <input type="text" value={inputValue} onChange={handleChange} />
    </div>
  );
}

```

Just keep in mind that the type of that variable is a string so if you want to use as a number you would have to convert it by using **parseInt()** javascript function.
