How to remove a JS mask from an input when submitting the form?

Asked

Viewed 454 times

-1

I have a small project done in Java using Springmvc and wanted one of the fields of a form to have the monetary input mask, but when I give Submit in the form it error in Binding with the model, because the field is in Bigdecimal and the characters placed by the mask go together. I’ve tried some plugins done in Jquery but so far nothing has helped...anyone know a plugin that suits me? Something that takes the dots out of the mask and replaces the comma with a dot when giving Submit...:

1.234,56 -------> 1234.56

  • VC can remove the dot (or the dots) and replace the comma by dot in the backend itself by submitting the form and receiving the value.

1 answer

0

You can try using the method replace, for example:

var a = "1.234,56"
a = a.replace(".", "")
a = a.replace(",", ".")
a = parseFloat(a)

In place of the variable a use the variable that is returns the value of your input.

  • Vlw Thales, it worked out bro, I just had to take the parseFloat because it was giving conflict in the Back with one of the business rules, but thank you very much brother!

  • @Nickfabrizzi don’t forget to mark as answered.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.