Well, I've tried many variations of regexes but the tests either 
always fail or always succeed, nothing in between. So I've resorted 
to testing for some of the unwanted characters and printing the error 
msg if those characters are found:

foreach my $i (keys %params)
{       if ($params{$i}=~m/\$/g || $params{$i}=~m/\%/g || 
$params{$i}=~m/\&/g || $params{$i}=~m/\//g || $params{$i}=~m/\\/g || 
$params{$i}=~m/\</g || $params{$i}=~m/\>/g || $params{$i}=~m/\{/g || 
$params{$i}=~m/\}/g || $params{$i}=~m/\^/g || $params{$i}=~m/\|/g)
     {
        print "Error msg";
     }
}

>       Here is some code which does what you want:
>
>#!perl -w
># A-Za-z0-9_@.-
>
>while ( 1 ) {
>   printf "Please enter data: ";
>   chomp(my $Input = <STDIN>);
>   last if ( $Input=~ /^ex/i );
>   if ( $Input =~ /[^\w\d\_@.\-\s]/g ) {
>      printf "You entered something other than the following:\n";
>      printf " A-Z a-z 0-9 _ \@ . -\n";
>      printf "You entered: <$Input>\n";
>      printf "Correct and re-enter\n";
>    }else {
>      printf "Good data entered!\n";
>    }
> }
>
>Wags ;)
>
>-----Original Message-----
>From: Teresa Raymond [mailto:[EMAIL PROTECTED]]
>Sent: Saturday, July 28, 2001 08:59
>To: [EMAIL PROTECTED]
>Subject: Re: regexp issues TR
>
>
>Let me rephrase what I want to do since I was so unclear the first
>time:  I want to output an error message every time the input
>includes characters that are not the following: A-Za-z0-9_@.- or a
>space(s).
>
>At this point, I've tried:
>
>       if ($params{$i} !~ /[^\w\@.-\s]/g) {
>       print "Error Message";
>}
>#output: prints error msg every time
>
>       unless ($params{$i} =~ /[^\w\@.-\s]/g) {
>       print "Error Message";
>}
>#output: prints error msg every time
>
>       if ($params{$i}=~m/^[\W&&[\@]&&[.]&&[-]]+$/g) {
>       print "Error Message";
>}
>#output: evaluates false with unallowed chars, never prints error msg
>
>>On Jul 25, Teresa Raymond said:
>>
>>>I tried the following code to test for bad characters but keep
>>>getting my error msg though the values passed do not contain chars
>>>that are not "A-Za-z0-9_@.-" (I also reread my last post and found
>>>that my English articulation was very poor, I'm grateful that anyone
>>>responded!).
>>
>>You're using !=, when you "meant" to use !~, but you really want to use =~
>>
>>>{if ($params{$i}!=m/[^\w@.-]/g)
>>
>>  if ($params{$i} =~ /[^\w\@.-]/) {
>>    # badness
>>  }
>>
>>--
>>Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
>>I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
>>Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
>>Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
>>Acacia Fraternity, Rensselaer Chapter.         Brother #734
>>**      Manning Publications, Co, is publishing my Perl Regex book      **
>
>*** Teresa Raymond
>*** http://www.mariposanet.com
>*** [EMAIL PROTECTED]
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

*** Teresa Raymond
*** http://www.mariposanet.com
*** [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to