0

As per the requirement, on keypress, I need to check everytime thousand seperator should not come after decimal seperator. Is it possible with regex. If yes then how?

  • Try my answer on a similar question: http://stackoverflow.com/questions/37694286/adding-two-decimal-places-using-javascript/37694423#37694423 – Oshadha Jun 10 '16 at 12:16
  • Welcome to StackOverflow! Please take the [tour](http://stackoverflow.com/tour) and read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask). Then come back and edit your question accordingly. – Jan Jun 10 '16 at 12:30

1 Answers1

0

Numeral.js - is a library that you can use for number formatting. With that you can format your number as follows:

numeral(10000).format('$0,0.00');

Hope this will help you.

Oshadha
  • 546
  • 10
  • 25
  • This library file will only help in formatting after writing a number. If someone is giving input with format i.e. 111,111,121.11, then It should check on keypress, he has given decimal seperator before thousand seperator or not. – Kishan Kumar Soni Jun 10 '16 at 18:06
  • What is your ultimate goal? Is it about formating the number with thousand separator? or just checking whether the user has separated it already? – Oshadha Jun 10 '16 at 18:11
  • As I understand you don't need to check whether the number is already formatted. If you are final goal is to format it with thousand separator. Just replace all the thousand separators and format it. This will be easier. Please let me if it is doable in your situation. – Oshadha Jun 11 '16 at 06:43
  • I know that how to format and unformat. if user is giving a number with formated pattern only, so I ensure that he will not do any mistake by giving any decimal seperator before thousand seperator. I want help for regex which will not allow this mistake. – Kishan Kumar Soni Jun 11 '16 at 07:15