Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript html正则表达式验证对十进制输入仅限制一个句点_Javascript_Html_Regex - Fatal编程技术网

Javascript html正则表达式验证对十进制输入仅限制一个句点

Javascript html正则表达式验证对十进制输入仅限制一个句点,javascript,html,regex,Javascript,Html,Regex,我做了一个只接受十进制的HTML输入 <input type="text" class="form-control" id="price" name="price" placeholder="Price" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"> 这是有效的。但是,我需要修改正则表达式以只接受一个句点 更正:9.999 错:9.9.99.99 有办法吗?请不要使用jquery validate和html

我做了一个只接受十进制的HTML输入

<input type="text" class="form-control" id="price" name="price" placeholder="Price" 
onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')">

这是有效的。但是,我需要修改正则表达式以只接受一个句点

更正:9.999

错:9.9.99.99


有办法吗?请不要使用jquery validate和html type=“number”(当您将输入设置为type number时,用户不需要向上和向下箭头),感谢分享此答案以限制十进制输入的一个句点

替换

this.value=this.value.replace(/[^0-9\.]/g,'')

this.value=this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')