Share
Explore BrainMass

Javascript Problem

EXAMPLE:

I use the function so when I fill in the form it checks that the date is an integer or the date is of length 8 (format ddmmyyyy.)
If it is neither 8 digits in length nor equal to the parsed value then the form cannot be validated and an error message is brought up. This function is called on form validation.

The problem is as follows:

When I enter a date not starting with 0 this function works as required however if the
date starts with 0 it will not validate as secondHold and holdString no longer equal. i.e.

textObj.value = 21081985 Then the validation works correctly and holdString == secondHold.

textObj.value = 01081985 Then the validation does NOT work and holdString != secondHold.

Could anyone please help give me aclue as to why this is?

Thanks

The function is as follows:
JC

function checkDate(textObj)
{
datetestCheck = 0;
holdString = textObj.value
secondHold = parseInt(holdString)
if (secondHold != holdString || holdString.length != 8)
{
datetestCheck = datetestCheck + 1;
return true
}
else
{
return false
}
}

Solution Preview

function checkDate(textObj)
{
datetestCheck = 0;
holdString = textObj.value
secondHold = parseInt(holdString,10)
if (secondHold != NaN || holdString.length != 8)
{
datetestCheck = datetestCheck + ...

$2.19