Gossamer Forum
Home : General : Perl Programming :

number validation

Quote Reply
number validation
let's say i have fields for 9 scores and 9 putts. i need to check each of these to be sure they're numeric or blank. if a field is blank, i want to change it to zero. then i need to compare the putts to the score to be sure the score is always greater than putts. i have tried a zillion things but cannot get it to work! i'm incrementing the scores in $in{"fs$k"} and putts in $in{"fp$k"} where k increments from 1 to 9. here is excerpt of my code:

Code:
my ($k) = 1;
while ($k < 10 ) {
$in{"fs$k"} =~ s/\s+$//g;
if (!$in{"fs$k"}) {$in{"fs$k"} = '0'; }
...

if (($in{"fs$k"} =~ /^[0-9]+$/) || ($in{"bs$k"} =~ /^[0-9]+$/)) { $score = 'Scores (must be numeric)<br>'; }
if (($in{"fp$k"} =~ /^[0-9]+$/) || ($in{"bp$k"} =~ /^[0-9]+$/)) { $putt1 = 'Putts (must be numeric)<br>'; }
if (($in{"fp$k"} > $in{"fs$k"}) || ($in{"bp$k"} > $in{"bs$k"})) { $putt2 = 'Putts (must be less than score)<br>'; }
++$k;
}
i keep getting the message that scores and putts must be numeric, even when i type numbers in every field and my putts are less than scores. please help!
Subject Author Views Date
Thread number validation delicia 6669 Mar 11, 2012, 7:34 AM
Thread Re: [delicia] number validation
delicia 6452 Mar 11, 2012, 8:43 AM
Thread Re: [delicia] number validation
Andy 6419 Mar 12, 2012, 4:40 AM
Post Re: [Andy] number validation
delicia 6398 Mar 14, 2012, 4:23 AM