Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The output from the script follows:#!/usr/bin/perl #supply test strings on the command line for ease $test1 = shift(@ARGV); sub validate_text { if ( $test1 =~ m/^[A-Za-z0-9\-\ ]+$/ ) { print "Text clean\n"; return ($test1); } else { $errorstring = "Funny business with variables occuring +, have attempted to fix"; print "$errorstring\n"; print "dollartest before fixing = $test1\n"; $test1 =~ s/^[^A-Za-z\-\ ]+$//g; print "dollartest after fixing = $test1\n"; return ($test1); } } $validated = &validate_text; print "the validated text is: $validated\n";
[lowprivuser@localhost testing]$ perl regexp-check2.pl abcd\"efg Funny business with variables occuring, have attempted to fix dollartest before fixing = abcd"efg dollartest after fixing = abcd"efg the validated text is: abcd"efg [lowprivuser@localhost testing]$ perl regexp-check2.pl abcdefg1 Text clean the validated text is: abcdefg1 [lowprivuser@localhost testing]$
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inverse regexes for input validation
by sgifford (Prior) on Mar 28, 2007 at 16:45 UTC | |
|
Re: Inverse regexes for input validation
by ikegami (Patriarch) on Mar 28, 2007 at 16:43 UTC | |
by chris-lon (Initiate) on Mar 28, 2007 at 17:00 UTC | |
by graff (Chancellor) on Mar 29, 2007 at 01:15 UTC | |
|
Re: Inverse regexes for input validation
by GrandFather (Saint) on Mar 28, 2007 at 21:34 UTC |