gpt4 book ai didi

javascript - isnan 函数接受点

转载 作者:行者123 更新时间:2023-11-28 20:29:21 25 4
gpt4 key购买 nike

isnan() 函数也接受 .(点)。如何预防它们。这是示例代码:

        var Price = $("#Price").val();            
if (Price == "") {

alert ("Required!");
}
else if (isNaN(Price)) {

$("#Price").val(Price);
alert("Enter digits");

}

我在文本框的 KeyUp 事件中调用此 JS 代码。

最佳答案

else if (!/^\d+$/.test(Price)) {
// only digits
}

关于javascript - isnan 函数接受点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16727620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com