简体   繁体   English

如何使用正则表达式验证防止用户在输入中输入逗号?

[英]How to prevent users from entering a comma in an input with regex validation?

I have a regex that allows only a number or dot.我有一个只允许数字或点的正则表达式。 Commas should be forbidden.逗号应该被禁止。

<input validator="/^\d{1,6}(\.\d{1,2})?$/" maxlength="11" validator-invoke="watch" 

在此处输入图片说明

在此处输入图片说明

This shows an error as expected, but what I actually want to achieve is to not even allow the user to enter a comma, or automatically delete the comma if the former is not possible.这显示了预期的错误,但我真正想要实现的是甚至不允许用户输入逗号,或者如果前者不可能,则自动删除逗号。

I would like to implement this in either AngularJS, HTML, or vanilla JavaScript, but it needs to work for IE.我想在 AngularJS、HTML 或 vanilla JavaScript 中实现它,但它需要适用于 IE。

How can I accomplish this?我怎样才能做到这一点?

这可以解决在文本框中不包含任何逗号值的问题。

<input type="number"/>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM