简体   繁体   中英

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.

How can I accomplish this?

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

<input type="number"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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