nitin88
nitin88

Reputation: 13

Regex Pattern to Match Currency Format - Javascript

I am newbie to javascript and struggling to write regex pattern for the requirement

2,4 = 24.00

2.4 = 2.40

2.4.5 = 2.40

2.5,5 = 2.50

2,5.7 = 25.70

45.56.34 = 45.56

13.,0 = 13.00

13,.0 = 13.00

Only digits and comma and dot are allowed. it doesn't matter how they enter But i have to convert this into proper currency format xxx,xxx,xxx,xx.xx

edited: to clarify doubts

Upvotes: 0

Views: 1639

Answers (2)

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26727

have a look at the below web site you will find the Regex you are looking for

http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3

Upvotes: 0

hsz
hsz

Reputation: 152206

Try with:

var input  = '2,4';
var output = parseFloat( input.replace(",", ".").replace("..", ".") ).toFixed(2);

Upvotes: 3

Related Questions