special character regex match
special character regex match
am 05.05.2011 11:56:46 von Agnello George
Hi
I got a form with and users and insert in textarea words like :
/word_word2/wordword_word.txt
/word1_word/wordword_word2.txt
/word_word/word2word_word.txt
but they should not be able to type the following in the text area
/
%
$
###
space
unless ( $files =~ /^\s+$/ || /[\_\/\@\$\#]/) {
print "yes ";
}
Thanks for all the help
--
Regards
Agnello D'souza
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special character regex match
am 05.05.2011 12:28:15 von Rob Dixon
On 05/05/2011 10:56, Agnello George wrote:
> Hi
>
> I got a form with and users and insert in textarea words like :
>
> /word_word2/wordword_word.txt
> /word1_word/wordword_word2.txt
> /word_word/word2word_word.txt
>
> but they should not be able to type the following in the text area
>
> /
> %
> $
> ###
> space
>
>
> unless ( $files =~ /^\s+$/ || /[\_\/\@\$\#]/) {
>
> print "yes ";
>
> }
I'm sorry, but I don't understand what your question is?
Rob
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special character regex match
am 05.05.2011 12:55:48 von Rob Coops
--20cf300fab9775945204a285387c
Content-Type: text/plain; charset=UTF-8
Ok let me try to understand the question.
You have a form (on an HTML page or inside an application, command line or
graphics?), this form contains a textarea that should not allow users to
freely enter text but the input should be scanned for "bad" characters, if
those are found the user should recieve a warning.
Regardless of the format the backend handling will be the same because you
have to assume a user will find a way to work around any frontend
limitations you impose and send the "bad" characters directly to your
backend application.
So lets see what we can do with characters:
/
%
$
###
space
use strict;
use warnings;
use Data::Dumper;
print Dumper check_input( '/' );
print Dumper check_input( '%' );
print Dumper check_input( '$' );
print Dumper check_input( '##' );
print Dumper check_input( ' ' );
print Dumper check_input( 'abcdefghijklmnopqrstuvwxyz' );
print Dumper check_input( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' );
print Dumper check_input( '1234567890' );
print Dumper check_input( '!@^&*()_+-=' );
print Dumper check_input( 'a A' );
sub check_input {
my $input = shift; # Take the input from @_
return 1 unless ( $input =~ /\/|%|\$|\#\#|\s/g ); # Return 1 if the input
is free of the "bad" characters
return 0; # Return 0 the input contained a "Bad" character
}
I think that should do the trick... but as Rob D. said your question is not
very clear so it might not be what you are looking for at all.
Regards,
Rob
On Thu, May 5, 2011 at 12:28 PM, Rob Dixon wrote:
> On 05/05/2011 10:56, Agnello George wrote:
>
>> Hi
>>
>> I got a form with and users and insert in textarea words like :
>>
>> /word_word2/wordword_word.txt
>> /word1_word/wordword_word2.txt
>> /word_word/word2word_word.txt
>>
>> but they should not be able to type the following in the text area
>>
>> /
>> %
>> $
>> ###
>> space
>>
>>
>> unless ( $files =~ /^\s+$/ || /[\_\/\@\$\#]/) {
>>
>> print "yes ";
>>
>> }
>>
>
> I'm sorry, but I don't understand what your question is?
>
> Rob
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
--20cf300fab9775945204a285387c--
Re: special character regex match
am 06.05.2011 08:04:26 von Brian Fraser
--bcaec52d51d722d89d04a29543da
Content-Type: text/plain; charset=ISO-8859-1
On Thu, May 5, 2011 at 7:55 AM, Rob Coops wrote:
> /\/|%|\$|\#\#|\s/g
>
Why not just a character class? It's usually a bad idea to use alternation
in these cases. m!^[/%#\s\$]+$! should do the trick. Or if there must be
three #'s in a row, perhaps m!^ (?: [/%\s\$]+ | \#{3} )+ $!x ?
In any case, you should consider if this is the right approach - There are
hundreds of characters you probably don't want ( (?{ `echo "Hope you didn't
use re 'eval';"` }) ), so the chance of going back and changing your program
is high; It's an uphill, never-ending battle.
Meanwhile, there only a handful of character that you actually want -
Mayhaps /^\p{L}+$/ will do the trick?
Brian.
--bcaec52d51d722d89d04a29543da--