简体   繁体   中英

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="">

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