Link to home
Start Free TrialLog in
Avatar of toddkeller
toddkeller

asked on

pricing form, "$000.00" needs to display up to $520.00 dollars but can be any amount entered up to that amount with the decimal?-any ideas?

i have a form for a friend of mine that needs to display numbers for an accounting program up to 520.00 dollars. the decimal point needs to be there.  is there a way to limit the first digit to 0-5, the second 0-9, and third 0-9?. the .00 is not for entering-it is just behind the first 3 numbers. if i had to expand it to a thousand or hundred thousand digits, would that be easy too?-
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toddkeller
toddkeller

ASKER

thanks so much!, that will work perfectly!.
t
roonaan, i think that i did not test your solution fully and i can't seem to get it to work when it goes beyond 520?- does it work right for you?- maybe i am srewing something up.?
Hi again,

There was indeed a grave error in the former code. However after some changes, and actually testing the code, I came up with the next which works.

function checkAmount(amntField)
{
   var val = amntField.value;
   var isIntVal = val.match(/^[0-9]{1,3}$/);
   var isFloatVal = val.match(/^[0-9]{1,3}\.[0-9]{1,2}$/)
   var isNum = isIntVal || isFloatVal;
   if(!isNum || val < 0 || val > 520)
   {
       alert('You have to enter an amount between 0.00 and 520.00');
       amntField.focus();
       return false;
   }
   return true;
}

This however allows any numeric value between 0.00 and 520.00 including values such as 10.1 or a plain 7. When you specifically need user to enter .00 or something at the end, please report back.

-r-
cool i will try this out tonight and get back to you ,
thanks!
t
Works great thanks!, i was wondering as a side note, is there a way to restrict users from entering letters at all and only numbers?-i know it's not a big deal but might make it easier if users accidentally hit letters?-what do you think?

Thanks for all the help i really appreciate it, and i learned alot from your example.-could you recomend a good online source for javascript?- i mean i use this site for sure!, but i was wondering if there was a good resource so that i could look up commands, their meaning and use?
thanks again,
t
Well, using javascript one could detect which key is pressed and possibly cancel that key. However there are some possible conflicts when choosing an approach as to which keys are allowed/disallowed:
- We define a set of allowed keys: Should we include hard return/backspace/tab?
- We define a set of disallowed keys: Which keys should we disallow?

<script type="text/JavaScript">
<!--
function doKey(key) {
  if (key >= 48 && key <= 57 || key == 46) {
          alert("You pressed a numeric key:" + key);
      //46 = dot.
  } elseif(key == 8 || key == 9 || key == 10 || key == 13) {
     //backspace=8
     //tab = 9
     //newline = 10
     //hard return = 13
  } else {
          return false;
  }
}
-->
</script>

<input type="text" onKeyPress="doKey(window.event.keyCode);" />
thanks!, i'll try that out and get back to you.-probably should not allow hard return/, backspace and tab are good.
-i imagine the main things to disallow are any letters, caps, shift, enter, alt,control, any of the f keys and windows keys?
-i'm not sure, i looked up the ascii:java glossary and saw what you were doing, but i'm not intelligent enough about the lanquage to code it up correctly.- i put it in conjuntion with a submit field to test on it's own and got bubcus.-when it works should it disallow you to even enter the letter keys?-like flash back to nothing once you enter them in?-just want to get a feel for what i am doing wrong.
-you know we could even take out the decimal entirely(46) and limit the text field entry to 3 numbers only(i did that and thought it might be simpler.)-but i can't get the dokey function itself to work-sorry man, i must be screwing it up somehow,
t