in reply to Inverse regexes for input validation
/^[^A-Za-z\-\ ]+$/ will only match if the string contains only bad characters.
sub validate_text { my ($text) = @_; if ($text =~ s/[^A-Za-z0-9 -]+//g) { print "Funny business fixed\n"; } else { print "Text was already clean\n"; } return $text; } my $validated = validate_text($test1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Inverse regexes for input validation
by chris-lon (Initiate) on Mar 28, 2007 at 17:00 UTC | |
by graff (Chancellor) on Mar 29, 2007 at 01:15 UTC |