[英]Regex Pattern to Match Currency Format - Javascript
I am newbie to javascript and struggling to write regex pattern for the requirement 我是javascript新手,正在努力为要求编写正则表达式模式
2,4 = 24.00 2,4 = 24.00
2.4 = 2.40 2.4 = 2.40
2.4.5 = 2.40 2.4.5 = 2.40
2.5,5 = 2.50 2.5,5 = 2.50
2,5.7 = 25.70 2,5.7 = 25.70
45.56.34 = 45.56 45.56.34 = 45.56
13.,0 = 13.00 13.,0 = 13.00
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
不管他们如何输入,但是我必须将其转换为正确的货币格式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 http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.