Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
こんにちは、JS で正規表現を使用して、入力を -9999 から 9999 までの正しい数値のみに制限する必要があります。ユーザーが次のような数字を入力できないようにします。
9-985 02564 1234-
ありがとう。
この正規表現は機能するはずです:
^-?\d{1,4}$
空の文字列は使用できません。0 を含む -9999 から 9999 までの数値を指定できます。
この式はオプションで a で始まり、-1 ~ 4 桁のみです。
-