ユーザーがウィンドウの幅を入力する必要があるフィールドがあります。16.75 から 48 の間で、.25 刻みである必要があります (したがって、.00、.25、.50、.75 で終わる必要があります)。番号 31.25 で正規表現をテストするために次のことを試みましたが、すべて false を返します。私はインターネットを荒らしましたが、私のような正規表現の初心者にはあまり助けが見つかりません。誰かがこれの正規表現を手伝ってくれますか?
フィールドは次のとおりです。
<input type="text" id="windowWidth" onchange="basePrice()">
JS は次のとおりです。
function basePrice()
{
var windowWidth = document.getElementById("windowWidth").value;
var windowHeight = document.getElementById("windowHeight").value;
if (windowWidth != "" && windowWidth > 16.75 && windowWidth < 48)
{
alert(/^\d{2}\.[00]$/.test(windowWidth));
alert(/^\d{2}\.[25]$/.test(windowWidth));
alert(/^\d{2}\.[50]$/.test(windowWidth));
alert(/^\d{2}\.[75]$/.test(windowWidth));
}
else
{
alert("error");
exit;
}
}