Re: Hi all, question about caracter detection

2002-11-22 Thread Tanton Gibbs
You could also use

return $_[0] !~ m/[^a-zA-Z0-9]/;

or

return $_[0] =~ m/^[a-zA-Z0-9]+\Z/;

the last one is clearer to me because you eliminate all of the negatives.
- Original Message - 
From: "Miguel Angelo" <[EMAIL PROTECTED]>
To: "Perl beginners" <[EMAIL PROTECTED]>
Sent: Friday, November 22, 2002 3:34 PM
Subject: RE: Hi all, question about caracter detection


> Hi All, 
> 
> thankx for the help (Sudarshan Raghavan and Beau E.
> Cox), i have found a generic solution
> 
> here is the sample script...
> #
> 
> #!/usr/bin/perl -wT
> 
> ##
> # modules
> ##
> use strict ;
> 
> 
> ##
> # Global Variables
> ##
> 
> 
> #
> # will recive a string are check agains a list of
> allowed values
> # Will return : 0 if only allowed chars were found
> #   1 if at least one invalid char is
> found 
> sub check_string { 
> 
> unless ( $_[0] =~ m/[^a-zA-Z0-9]/ ) {
> 
> return 0;
> }
> 
>   return 1; 
> }
> 
> ##
> # Main
> ##
> my $STRING = "askdnj\nasj";
> 
> print "\n(0 is ok, 1 means invalid chars) : ";
> print check_string("$STRING");
> print "\n";
> 
> 
> ###
> 
> 
> Stay well all
> Miguel Angelo
> 
> 
> 
> 
> 
>  
> 
>  --- Sudarshan Raghavan <[EMAIL PROTECTED]> wrote:
> > On Mon, 18 Nov 2002, Beau E. Cox wrote:
> > 
> > > Hi -
> > > 
> > > This will 'strip' all but a-zA-Z0-9:
> > > 
> > > #!/usr/bin/perl
> > > 
> > > use strict;
> > > use warnings;
> > > 
> > > my $STRING = "kjsh234Sd\nki";
> > > 
> > > $STRING =~ s/[^a-zA-Z0-9]//sg;
> > > 
> > > print "$STRING\n";
> > > 
> > > the ~ makes the character class negative, 
> > 
> > I guess you meant ^, not ~
> > 
> > > the s makes
> > > the regex examine new lines, and g means global.
> > 
> > You need an /s when you want . to match newlines
> > (which it
> > normally doesn't). In this case since you are not
> > using a
> > .., /s is not needed.
> > 
> > $STRING =~ s/[^a-zA-Z0-9]//g;
> > The above will work just fine
> > 
> > You can also use tr/// for this
> > $STRING =~ tr/a-zA-Z0-9//cd;
> > 
> > If the OP just wants to check not replace either of
> > these should
> > do
> > unless ($STRING =~ m/[^a-zA-Z0-9]/) {
> ># Valid STRING
> > }
> > 
> > or 
> > 
> > unless ($STRING =~ tr/a-zA-Z0-9//c) {
> ># Valid STRING
> > }
> > 
> > 
> > 
> > 
> > -- 
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> >  
> 
> =
> *
> * Miguel Angelo *
> * E-mail: [EMAIL PROTECTED] *
> * Domain: http://migas.mine.nu  *
> *
> 
> __
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
> 
> -- 
> 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]




RE: Hi all, question about caracter detection

2002-11-22 Thread Miguel Angelo
Hi All, 

thankx for the help (Sudarshan Raghavan and Beau E.
Cox), i have found a generic solution

here is the sample script...
#

#!/usr/bin/perl -wT

##
# modules
##
use strict ;


##
# Global Variables
##


#
# will recive a string are check agains a list of
allowed values
# Will return : 0 if only allowed chars were found
#   1 if at least one invalid char is
found 
sub check_string { 

unless ( $_[0] =~ m/[^a-zA-Z0-9]/ ) {

return 0;
}

return 1; 
}

##
# Main
##
my $STRING = "askdnj\nasj";

print "\n(0 is ok, 1 means invalid chars) : ";
print check_string("$STRING");
print "\n";


###


Stay well all
Miguel Angelo





 

 --- Sudarshan Raghavan <[EMAIL PROTECTED]> wrote:
> On Mon, 18 Nov 2002, Beau E. Cox wrote:
> 
> > Hi -
> > 
> > This will 'strip' all but a-zA-Z0-9:
> > 
> > #!/usr/bin/perl
> > 
> > use strict;
> > use warnings;
> > 
> > my $STRING = "kjsh234Sd\nki";
> > 
> > $STRING =~ s/[^a-zA-Z0-9]//sg;
> > 
> > print "$STRING\n";
> > 
> > the ~ makes the character class negative, 
> 
> I guess you meant ^, not ~
> 
> > the s makes
> > the regex examine new lines, and g means global.
> 
> You need an /s when you want . to match newlines
> (which it
> normally doesn't). In this case since you are not
> using a
> .., /s is not needed.
> 
> $STRING =~ s/[^a-zA-Z0-9]//g;
> The above will work just fine
> 
> You can also use tr/// for this
> $STRING =~ tr/a-zA-Z0-9//cd;
> 
> If the OP just wants to check not replace either of
> these should
> do
> unless ($STRING =~ m/[^a-zA-Z0-9]/) {
># Valid STRING
> }
> 
> or 
> 
> unless ($STRING =~ tr/a-zA-Z0-9//c) {
># Valid STRING
> }
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>  

=
*
* Miguel Angelo *
* E-mail: [EMAIL PROTECTED] *
* Domain: http://migas.mine.nu  *
*

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

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




RE: Hi all, question about caracter detection

2002-11-18 Thread Sudarshan Raghavan
On Mon, 18 Nov 2002, Beau E. Cox wrote:

> Hi -
> 
> This will 'strip' all but a-zA-Z0-9:
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
>   my $STRING = "kjsh234Sd\nki";
> 
>   $STRING =~ s/[^a-zA-Z0-9]//sg;
> 
>   print "$STRING\n";
> 
> the ~ makes the character class negative, 

I guess you meant ^, not ~

> the s makes
> the regex examine new lines, and g means global.

You need an /s when you want . to match newlines (which it
normally doesn't). In this case since you are not using a
.., /s is not needed.

$STRING =~ s/[^a-zA-Z0-9]//g;
The above will work just fine

You can also use tr/// for this
$STRING =~ tr/a-zA-Z0-9//cd;

If the OP just wants to check not replace either of these should
do
unless ($STRING =~ m/[^a-zA-Z0-9]/) {
   # Valid STRING
}

or 

unless ($STRING =~ tr/a-zA-Z0-9//c) {
   # Valid STRING
}




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




RE: Hi all, question about caracter detection

2002-11-18 Thread Beau E. Cox
Hi -

This will 'strip' all but a-zA-Z0-9:

#!/usr/bin/perl

use strict;
use warnings;

my $STRING = "kjsh234Sd\nki";

$STRING =~ s/[^a-zA-Z0-9]//sg;

print "$STRING\n";

the ~ makes the character class negative, the s makes
the regex examine new lines, and g means global.

Aloha -> Beau.

-Original Message-
From: Miguel Angelo [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 2:31 AM
To: [EMAIL PROTECTED]
Subject: Hi all, question about caracter detection


Hi All,

Thankx for reading this.

I have a very newbie question...

i'm working on a CGI and i want only to permit some
caracters by the user...

imagine

my $STRING = "kjsh234Sd\nki";

# now i want to check if there is any invalid caracter
# in this case a-z ; A-Z and 0-9

there for /[a-zA-Z0-9]/ but i am unable to find a
valid command for that, the \n always passes, i
definity do not want to use execption on what o do not
allow, i want only to allow some caracters
invalidating all others...

here what i have tried

if ( $STRING =~ /[a-zA-Z0-9]/ ) { etc }

my $count = ( $STRING =~ tr /a-zA-Z0-9// );

all failed...

please help me :)





=
*
* Miguel Angelo *
* E-mail: [EMAIL PROTECTED] *
* Domain: http://migas.mine.nu  *
*

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
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]