PDA

View Full Version : validate currency textbox


ammweb
01-26-2009, 06:52 PM
I am wanting to validate a text box if the amount keyed in is under $15.00 an alert box pops up.

I have 5 radio buttons when the radio button for the text box is selected, I only want amount of $15.00 or more entered. If not, a message telling them $15.00 minimum. I have a script but it is validating anything after the decimal.

Can someone explain what I need to change in the script?

<script language="JavaScript">
function checkForInvalid(obj) {
if ( /[^0-14\-]|-{2,}/gi.test(obj.value) ) {
alert("$15.00 minimum offering allowed")
obj.focus();
// obj.select(); // lined removed
return false;
}
return true;
}

</script>

Philip M
01-26-2009, 07:31 PM
This is not the correct place to post Javascript questions. That's the second time today!

Please look at:-

http://www.codingforums.com/showthread.php?t=17515

This is a category for seasoned JavaScripters to post a useful script or code snippet to benefit the public or for critiquing. The emphasis here is "seasoned" and "useful." For those new to JavaScript, this is not the forum to showcase "my first script", or ask for help debugging one.

I am feeling in a good mood today, and at least you added the <code> tags, so here is the script you need:-

<script type = "text/JavaScript">

function checkForInvalid(obj) {
var amt = parseFloat(obj.value,10);
if ((isNaN(amt)) || (amt < 15)) {
alert ("$15.00 minimum offering allowed")
obj.focus();
return false;
}
return true;
}

</script>

Hopefully a mod will move this over to the correct forum.



“Going to church does not make you a Christian anymore than going to the garage makes you a car.”
Dr. Laurence J. Peter (American "hierarchiologist", Educator and Writer, 1919-1990)

ammweb
01-26-2009, 10:11 PM
I am sorry for the posting. I should post future questions under
DOM and JSON scripting category---is that correct?

Philip M
01-27-2009, 01:28 PM
I am sorry for the posting. I should post future questions under
DOM and JSON scripting category---is that correct?

No. Javascript Programming.

This Post a Javascript is a specialised sub-forum of that.