テキスト ボックスを検証しようとしています。ユーザーに 0.1 から 4.0 の間でのみ入力してもらいたいのですが、次の正規表現を使用しています。
^[0-4](\.[0-9]+)?$
問題は、4.1などを4.9まで受け入れることです。
これを修正する方法についてのアイデアをお願いします
ありがとう
これを試して
^(?:[0-3](?:\.[0-9]+)?|4(?:\.0)?)$
編集
非キャプチャ グループを追加しました。
そして、CyprUS が尋ねたように、ここに説明があります。元の正規表現を 3.9 までに制限し、4(.0) の別の条件を追加しました。
NODE EXPLANATION
^ //the beginning of the string
(?: //group, but do not capture:
[0-3] //any character of: '0' to '3'
(?: //group, but do not capture (optional):
\. //'.'
[0-9]+ //any character of: '0' to '9' (1 or more times)
)? //end of grouping
| //OR
4 //'4'
(?: //group, but do not capture (optional):
\. //'.'
0 //'0'
)? //end of grouping
) //end of grouping
$ //before an optional \n, and the end of the string