Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

float validation

Status
Not open for further replies.

rtnMichael

Programmer
Aug 5, 2002
152
US
Hey guys, is it any different to validate floats as it is to validate integers? I have a form with three text boxes: upper and lower specs and an input box for a user input value. For example, an upper is 1.2345 and a lower is 1.0293. I want to check to see if the value input is between the two specs. Would it be any different to check against these values because they're floats?

Thanks
Mike

Here's what I have, don't know if it's right....well, can actually say it doesn't work right, I don't get the desired Pass/Fail I want.

function figurepassfail(ValueArr, Value_LowerArr, Value_UpperArr, max_parms)
{
var j = 0;
var flag;
PassFailArr = new Array();

while(j < max_parms)
{
flag = true;

if(!ValueArr[j])
{
}

else
{
//just to test if the uppers and lowers exist
if(Value_UpperArr[j] && Value_LowerArr[j])
{
if((ValueArr[j] > Value_UpperArr[j]) || (ValueArr[j] < Value_LowerArr[j]))
{
flag = false;
PassFailArr[j] = &quot;Fail&quot;;
}

else PassFailArr[j] = &quot;Pass&quot;;

}

else if(Value_UpperArr[j] && !Value_LowerArr[j])
{
if(ValueArr[j] > Value_UpperArr[j])
{
flag = false;
PassFailArr[j] = &quot;Fail&quot;;
}

else PassFailArr[j] = &quot;Pass&quot;;

}

else if(Value_LowerArr[j] && !Value_UpperArr[j])
{
if(ValueArr[j] < Value_LowerArr[j])
{
flag = false;
PassFailArr[j] = &quot;Fail&quot;;
}

else PassFailArr[j] = &quot;Pass&quot;;

}
}
j = j + 1;
}

document.form3.PassFail_str.value = PassFailArr;
return flag;
}
 
Why is this so complex? Am I missing something?

function checkNum(){
upperNum = document.myForm.upperNum.value
lowerNum = document.myForm.lowerNum.value
midNum = document.myForm.midNum.value
if (!isNaN(upperNum) && !isNaN(lowerNum) && !isNaN(midNum){
if (parseFloat(lowerNum) < parseFloat(midNum) && parseFloat(midNum) < parseFloat(upperNum)){
alert(&quot;all good&quot;)
}
else{
alert(&quot;No good&quot;)
}
}
else{
alert(&quot;Bad Data&quot;)
}
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
ok, quick question, I see that isNaN doesn't care if the values are not there. What do I do if the value isn't entered?
 
if (!isNaN(upperNum) && !isNaN(lowerNum) && !isNaN(midNum) && upperNum != &quot;&quot; && lowerNum != &quot;&quot; && midNum != &quot;&quot; ){

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
yeah, see I have been having a bad 2 weeks, you would think I would have thought of something so obvious!!!! [bugeyed]

Thanks for all the help
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top