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]