User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 363,440 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,205 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 849 | Replies: 4
Reply
Join Date: Apr 2008
Posts: 9
Reputation: trient is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
trient trient is offline Offline
Newbie Poster

decimal (10,2) limit

  #1  
Apr 25th, 2008
How to limit the user to decimal (10,2) when he enters number in the textfield?

Can anyone show how to do it in javascript?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Location: Madrid - Spain
Posts: 20
Reputation: HenryGR is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
HenryGR's Avatar
HenryGR HenryGR is offline Offline
Newbie Poster

Re: decimal (10,2) limit

  #2  
Apr 26th, 2008
Please specify a bit more.
Do you already have a sort of validation function?
You keep going, have a Nice day!
Henry.

Before printing this message, make sure is necessary.
Reply With Quote  
Join Date: Apr 2008
Posts: 9
Reputation: trient is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
trient trient is offline Offline
Newbie Poster

Re: decimal (10,2) limit

  #3  
May 1st, 2008
no i dont have validation function
how to restrict so that the currency can be limit to (10,2) decimal
Reply With Quote  
Join Date: Mar 2008
Location: Madrid - Spain
Posts: 20
Reputation: HenryGR is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
HenryGR's Avatar
HenryGR HenryGR is offline Offline
Newbie Poster

Re: decimal (10,2) limit

  #4  
May 1st, 2008
From your message, I conclude that your problem is that Javascript does not understand that for you, "10,2" equals "10.2".
Here I wrote a sample html, but the important part is the javascript function that checks the value.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>No title</title>
<script type="text/javascript" language="javascript">
	function curcheck(curf,maxval) {
		
		textcur = curf.value.toString();
		
		textcur += '';
		x = textcur.split(',');
		textcur = x[0]+'.'+x[1];
		if(Number(textcur) > maxval) {
			say('result',false); 
			return 
		}
		say('result',true);
	}

function say(were,val) {

	text = ( val ) ? "Valid value entered" : "Invalid value entered" ;
	eval("document.getElementById('"+were+"').innerHTML = text");
	
}
</script>
</head>

<body>
<form id="myform" action="" >
	<input type="text" size="4" id="currency" onchange="curcheck(this,10.2);" />
	<p id="result">&nbsp;</p>
</form>
</body>
</html>

Hope this is what you need.
You keep going, have a Nice day!
Henry.

Before printing this message, make sure is necessary.
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 438
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 61
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: decimal (10,2) limit

  #5  
May 1st, 2008
You would test the form field with a regex like this.
(10, 2) in database means 10 numbers, 2 decimal places. so 12345678.90 is valid.
  1. var testRegEx = /[0-9]{1,8}\.?[0-9]{0,2}/
  2. var isValidNumber = form.formField.value.match(testRegEx);
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:18 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC