Wednesday 15 April 2015

javascript - How to make an input field only take feasible dollar amounts -


Hey I'm trying to create an input field in javascript that has the rail back end,

$ 100.24

How can I pull it out? Currently a person can put more in several decimal points is. Hope this question is not very unclear.

Bind this function to an annotation event in your text field. It will parse the value of the field as a float and remove any number after 2 decimals. You can also use input type = "number" to prevent the string as an input.

Needless to say, it requires server-side verification, the user can easily disable JavaScript and input type: if this data comes back to your server, then expect it to work. Will never be.

  function check (e) {e.value = parseFloat (e. Value) .toFixed (2)}   

working jsfiddle :.


Input: 123456 - Result: 123.456

Input: 12,3456 - Result: 12,34

No comments:

Post a Comment