Forum Moderators: open

Message Too Old, No Replies

Validate specific inputs in Form

1598 < Strict number < 2800

         

purefan

5:35 pm on Dec 31, 2005 (gmt 0)

10+ Year Member



hello.
I have a form with several inputs (text, select)
I am validating them but in 2 specific ones I need to make sure the user entered only numbers between 1598 and 2800.
Those 2 inputs are named and IDed: WhiteElo and BlackElo.
Here is the code Im using:

////////////Start of Code
function validate(isForm){
var chares;
n = 0;
nElements = isForm.length;
for (i=0; i<nElements; i++)
{
if (isForm[i].type!= 'file')
{

if (isForm[i].value == "")
{
isForm[i].style.backgroundColor = 'green';
alert('Falta informacion');
isForm[i].focus();
return false
}//If is empty
else if(isForm[i].name=="WhiteElo" && (isNaN(parseInt(isForm[i])) ¦¦ isForm[i].value<1599 ¦¦ isForm[i].value>2800))
{alert("White Elo error. Its value is: " + isForm[i].value);isForm[i].focus();return false}
else
{
isForm[i].style.backgroundColor = 'white'
}

}//if not file
}//for
return true
}//validate
//////////////end of code

However even when I enter a valid number it keeps telling its wrong...
so...where's my mistake!?
thanks for your time

Bernard Marx

4:08 pm on Jan 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



isNaN(parseInt(isForm[i].[blue]value[/blue])) 

..also

isForm[i].value<159[blue]8[/blue]

(The type conversion is done implicitly, so you're OK there)

purefan

5:24 pm on Jan 1, 2006 (gmt 0)

10+ Year Member



thanks a lot! it works now
=D
Happy holidays!