I'm doing a simple pattern match to insure that form input contains only alpha-numeric characters. Wondering which pattern matching operators I should be using? The match is:

Code

if ($$InputPointer{'password'} =~ m/[^a-zA-Z0-9]/operators) { &PrintPage("Invalid Password", "", "Passwords may only contain letters or numbers. Please use you browser's BACK button to enter a different password."); exit; }

I'm thinking I should use g because I want it to check every character, o because the match won't change the value I am testing, and s because the string being tested is a single word.

Also, does it make a difference which order the operators are specified in? IE is m/pattern/ixm the same as m/pattern/mix?

Advanced thanks.

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!

I'm thinking I should use g because I want it to check every characteryes , g means "global" and will check the whole string...

o because the match won't change the value I am testingi do not know about this operator?? personally i have never used it in a check for password or username. but i do not want to say for sure that it is not needed.

and s because the string being tested is a single wordi believe you are confusing this with the \s operator that is used for verification in the operator. example: if ($password =~ /\s/g) {print "your password cannot have spaces"}

but then again i may be wrong..

Also, does it make a difference which order the operators are specified inno, you can put them in ANY order.

did you test your code? I guess not. The regex you specified will match any string that contains at least one alphanumeric character. First, the \d is redundant, because it's part of \w. Second, as I said before, you don't check if the whole string is made of alphanumerics. The correct check would be:

I'm a bit late replying to this, but perhaps it helps. Regular expressions sometimes look easier than they are. Unless you understand how a regex engine works, you'll rarely understand regexes in all their detail. What you want to do can be easily done by saying:

You don't need any pattern matching modificators, like g, o, s, m, or whatever. The g modificator makes only sense within loops:

Code

my $string = 'Hello World'; print "$1\n" while $string =~ /(\w+)/g;

would print

Code

Hello World

while

Code

my $string = 'Hello World'; print "$1\n" if $string =~ /(\w+)/g;

would only print

Code

Hello

The o modificator isn't required because your regular expression doesn't contain variables that could be interpolated. It has nothing to do with the changing of the value you are matching. The s modificator is only required if you want the dot '.' to also match the newline character. This is only useful if you string can contain newlines and you're using the dot '.' to match an arbitrary character. To the best of my knowledge, the modificator order is not of importance. Also, you can specify modificators more than once. So m/pattern/iiixx is the same as m/pattern/xi. I hope this helps.

I'm replying to my own post just because I wasn't able to edit it anymore. I just wanted to apologize for treating 'Guru' kinda rude in my post. (Compared to his one I'm rather polite, but unfortunately 90% of it were taken out and I didn't quote it as a whole.) But I've been quite upset, because I can't stand if (someone posts wrong code) AND (the same person throws flame-like posts to me when I point out the errors in their post) AND (the person cowardly withdraws). If someone tells me that

Code

=begin cite_i_dont_remember_so_well you as a journeyman know jack [..] about regexes =cut

and hasn't at least verified the mistakes I showed up by having a look at the manpages, I think I have the right to be upset. I absolutely don't mind if anyone makes mistakes. I had two posts this week where I was writing crap. (Not really crap, but code that could be enhanced...) But I rather rewarded the people who replied to me for showing me that what I did was wrong. So again, sorry for the rude post.