gpt4 book ai didi

jquery - 如何使用 jquery 和 regex 验证小数字段?

转载 作者:行者123 更新时间:2023-12-01 07:26:32 24 4
gpt4 key购买 nike

这是我到目前为止所拥有的:

$j(element)..keypress(function(e){
var val = $j(this).val();
if (("1234567890.").indexOf(e.charCode) > -1){
if (val.length > 0){
var regex = /(\+|-)?(\d*\.\d*)/;
if (regex.test(val)){
return true;
} else {
return false;
}
} else {
return true;
}
} else {
return false;
}
});

但由于某种原因,文本字段只允许一个字符......甚至不允许数字

最佳答案

这会检查十进制数,并带有可选的 +/- 符号字符。谷歌搜索不到5秒就找到了。/^\s*(\+|-)?((\d+(\.\d+)?)|(\.\d+))\s*$/

关于jquery - 如何使用 jquery 和 regex 验证小数字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9204783/

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