in reply to Regex an Array?
'11, 22, 33, 44, 55' is a string (not an array), so
$INPUT{'checked_ids'} =~ /^(?:\s*[0-9]+\s*,)\s*[0-9]+\s*$/
will do what you want.
Once validated (as shown above), you can convert the list to an array as follows:
@checked_ids = $INPUT{'checked_ids'} =~ /(\d+)/g
If you really did need to check an array:
my $bad; foreach (@array) { unless (/regexp/) { $bad = 1; last; } } die("Naughty\n") if $bad;
or
my $num_bad = grep { !/regexp/ } @array; die("$num_bad naughties\n") if $num_bad;
|
|---|