如何从用户端输入文本框时获取货币格式

如何从用户端输入文本框时获取货币格式

本文介绍了如何从用户端输入文本框时获取货币格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够得到解决方案,请尽快帮助我...

我试过这个10000000,输出是1,0,0,0,0,000但是我需要输出像这样1,00,00,000 



提前谢谢



我尝试过:



 function ValidateAmount(txt){
var key;
if(window.event)
key = window.event.keyCode; // Chrome或IE仅
if(key == 32){
// alert(White Space Not Allowed);
var str = document.getElementById(txt.id).value;
str = str.replace(/ \ s / g,'');
document.getElementById(txt.id).value = str;
}

str = document.getElementById(txt.id).value;

str = str.toString();
var lastThree = str.substring(str.length - 3);
var otherNumbers = str.substring(0,str.length - 3);
if(otherNumbers!='')
lastThree =','+ lastThree;
var res = otherNumbers.replace(/ \B(?=(\d {2})+(?!\ d))/ gi,,)+ lastThree;
document.getElementById(txt.id).value = res;
}
解决方案

i am able to get solution please help me soon...

i tried this for 10000000, Output is 1,0,0,0,0,000 But i need Output Like this 1,00,00,000


Thanks in advance

What I have tried:

function ValidateAmount(txt) {
			var key;
			if (window.event)
				key = window.event.keyCode; // Chrome or IE only
			if (key == 32) {
				//alert(" White Space Not Allowed ");
				var str = document.getElementById(txt.id).value;
				str = str.replace(/\s/g, '');
				document.getElementById(txt.id).value = str;
			}

			str = document.getElementById(txt.id).value;
			
			str = str.toString();
			var lastThree = str.substring(str.length - 3);
			var otherNumbers = str.substring(0, str.length - 3);
			if (otherNumbers != '')
				lastThree = ',' + lastThree;
			var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/gi, ",") + lastThree; 
			document.getElementById(txt.id).value = res;
}
解决方案


这篇关于如何从用户端输入文本框时获取货币格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 20:36