Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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;
}
Posted
Updated 16-Jun-18 4:41am
v2

1 solution

Below is simiar posting with solution, it should help you

Automatically add Commas to a Number in a TextBox | DotNetCurry[^]
 
Share this answer
 
Comments
AnilvarmA pelluri 20-Jun-18 3:55am    
Thank You!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900