in reply to Alternatives to Data::Validator::Item
my $this_is_bad = '../A#\/*Bad|-Name'; my $this_is_ok = 'John Smith'; $this_is_bad = untaint($this_is_bad, '0-9a-zA-Z \_\-'); $this_is_ok = untaint($this_is_ok, '0-9a-zA-Z \_\-'); print 'Bad input at $this_is_ok' if !$this_is_ok; print 'Bad input at $this_is_bad' if !$this_is_bad; # if the input did not pass the veriable retured is blank sub untaint { my $value = shift || ''; my $pattern = shift || '0-9a-zA-Z\_'; return '' unless $value; $value !~ m!^([$pattern]+)$!i ? return : return $1; }
|
|---|