Dear Group,
I have a text field that I wish to cellect numbers of bird seen. However,
some folk want to use 'c' before the number or '+' after to indicate a fuzzy
number. I have tried creating a function that checks for each of these and
still validates the rest as a number:
function checkNumber( an_item )
{
count_val = an_item.value;
len = count_val.length;
count = "";
if (count_val.charAt(0) == "c"){
count = count_val.substring(1,len);
} else if (count_val.charAt(len-1) == "+"){
count = count_val.substring(0,len-1);
} else {
count = count_val;
}
if (isNaN (count)) {
msg = "Error: " + count + " is not a valid number for the Count
field";
alert (msg);
an_item.value = "";
return false;
} else {
count_num = parseInt (count);
if ((count_num < 1) || (count_num > 999999)) {
msg = "Error: The number in the Count field must be\nbetween 1 and
999,999";
alert (msg);
an_item.value = "";
return false;
}
}
}
This seems to work if I enter c1000 and 1000+ birds (both accepted), and
also if I enter ca1000 it catches that. But, it seems to accept +1000 and I
can't explain why. Any takers for an improvement? For info, I'll be handling
the 'c' and '+' later, but I just need to make sure it is only these options
(other than a pure number) that come through.
Thanks
Iain
--
__________________________________________________ _________
Iain Downie
British Trust for Ornithology, The Nunnery,
Thetford, Norfolk IP24 2PU, UK ® Charity No. 216652
Tel: +44 (0)1842 750050, fax: +44 (0)1842 750030
BirdWeb Gateway: http://www.bto.org/birdweb