简体   繁体   English

如何使用 JS 验证逗号作为小数分隔符的输入?

[英]How to validate input for comma as decimal separator using JS?

I am currently using this to allow users to enter numbers, but this accepts multiple dots and commas and I'd love to restrict it to a more precise number entry, because God knows the wonders that users can do.我目前正在使用它来允许用户输入数字,但是它接受多个点和逗号,我很想将其限制为更精确的数字输入,因为上帝知道用户可以做的奇迹。

How can I restrict it to comma as decimal separator?如何将其限制为逗号作为小数分隔符?

 <input oninput="this.value=this.value.replace(/[^0-9.,]+/gmi,'')" value="">

Thanks in advance!提前致谢!

Try following code:试试下面的代码:

<input onChange="this.value=this.value.replace(/[^A-Z0-9]+/ig, '')" value="">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 计算结果 Js 和输入字段中的小数/千位分隔符(点和逗号) - Decimal / Thousand separator (dot and comma) in the calculation results Js and Input field 如何在ios 6中给逗号(,)分隔符作为小数分隔符? - how to give comma(,) separator as decimal separator in ios 6? jQuery 验证插件:使用逗号作为小数点分隔符验证十进制数 - jQuery Validation Plugin: validate decimal number with comma as decimal separator Ant 设计 - 带逗号小数分隔符的货币输入 - Ant Design - Currency Input with comma decimal separator 如何使用逗号为 Input onChangeText React Native 验证十进制? - How to validate decimal with comma for Input onChangeText React Native? AngularJS:将小数点分隔符更改为逗号 - AngularJS: Change decimal separator to comma 如何在Javascript中将浮点小数点从点转换为逗号 - How to convert floating point decimal separator from dot to comma in Javascript 使用jQuery / JS键入时,使用1000个分隔符和2个小数位设置货币输入的格式? - Format currency input with 1000 separator and 2 decimal places upon typing using jQuery/JS? 如何验证小数值输入? - How to validate a decimal value input? 如何使用Parsley JS验证文件输入? - How to validate file input using Parsley JS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM