decimal (10,2) limit

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Apr 2008
Posts: 13
Reputation: trient is an unknown quantity at this point 
Solved Threads: 0
trient trient is offline Offline
Newbie Poster

decimal (10,2) limit

 
0
  #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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 24
Reputation: HenryGR is an unknown quantity at this point 
Solved Threads: 4
HenryGR's Avatar
HenryGR HenryGR is offline Offline
Newbie Poster

Re: decimal (10,2) limit

 
0
  #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 Quick reply to this message  
Join Date: Apr 2008
Posts: 13
Reputation: trient is an unknown quantity at this point 
Solved Threads: 0
trient trient is offline Offline
Newbie Poster

Re: decimal (10,2) limit

 
0
  #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 Quick reply to this message  
Join Date: Mar 2008
Posts: 24
Reputation: HenryGR is an unknown quantity at this point 
Solved Threads: 4
HenryGR's Avatar
HenryGR HenryGR is offline Offline
Newbie Poster

Re: decimal (10,2) limit

 
0
  #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.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <title>No title</title>
  6. <script type="text/javascript" language="javascript">
  7. function curcheck(curf,maxval) {
  8.  
  9. textcur = curf.value.toString();
  10.  
  11. textcur += '';
  12. x = textcur.split(',');
  13. textcur = x[0]+'.'+x[1];
  14. if(Number(textcur) > maxval) {
  15. say('result',false);
  16. return
  17. }
  18. say('result',true);
  19. }
  20.  
  21. function say(were,val) {
  22.  
  23. text = ( val ) ? "Valid value entered" : "Invalid value entered" ;
  24. eval("document.getElementById('"+were+"').innerHTML = text");
  25.  
  26. }
  27. </script>
  28. </head>
  29.  
  30. <body>
  31. <form id="myform" action="" >
  32. <input type="text" size="4" id="currency" onchange="curcheck(this,10.2);" />
  33. <p id="result">&nbsp;</p>
  34. </form>
  35. </body>
  36. </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 Quick reply to this message  
Join Date: Apr 2005
Posts: 1,426
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 230
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: decimal (10,2) limit

 
0
  #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 y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC