Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert a comma to dot automatically?

When the user enters a comma in the INPUT, I would like the comma to be automatically transformed in a dot. Is it possible?

<label>Number </label>
<input type="number" maxlength="5" />

Here is a reproduction -> Link

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

<input> elements of type number are used to let the user enter a number. They include built-in validation to reject non-numerical entries.

The user cann’t input comma in the INPUT, so first you have to change input type as text. after that on onkeyup event you can replace the value like below:

<input type="text" onkeyup="this.value=this.value.replace(/,/g, '.');"/>

https://stackblitz.com/edit/angular-ivy-hc3mn8?file=src/app/app.component.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading