简体   繁体   中英

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

Try with:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM