0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

入力フォーム(Input)で文字数(桁数)の制限をかける

Posted at

(例)「金額入力フォーム」で4桁(9,999円)までしか入力させたくないとき。

onChangeでe.target.value.length <= 4の場合のみステートにセットする。

→ 4桁までしか入力できなくなる。(4桁までしかステートに保存できなくなる。)

<PriceForm
  label={
    <div>
      金額
      <br />
      <div className="ml-14 text-xs"></div>
    </div>
  }
  placeholder="300"
  witdh="w-1/3"
  type="number"
  min={0}
  max={9999}
  value={price}
  onChange={(e) => {
    if (e.target.value.length <= 4) {
      setPrice(e.target.value);
    }
  }}
/>
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?