You need to match the whole string, not just part of it.

$str =~ /^[A-Za-z0-9_]+$/

The ^ will match the beginning of the string, and the $ will match a newline
or the end of the string.  Usually, the newline doesn't come into play as
you normally chomp( $str ) before comparing.

Tanton
----- Original Message -----
From: "bioinfo Gu" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, October 30, 2002 9:49 AM
Subject: Re: pattern matching


>
> Hi Jonathan,
> Thank you very much for your reply. I check your script, it did not work:
for example: Suppose I give the string "abc", "abc123" "123" "abc_123"
"abc.123": The string "abc", "abc123", "123", "abc-123" should be legal, but
the "abc.123" should be NOT legal. I am using perl script to open user
account, and check if user ID are legal or not. I just allow user ID include
letters, numbers and underscore(_), excluding all other characters such as:
!@#$%^&*(): all these stuff.
> But use script: if ($str =~ /[A-Za-z0-9\_]+/) { print "legal"; } else
{print "Illegal";}  It will print "Legal" with all the strings "abc"
"abc123" "123" "abc_123" "abc.123"
> Thanks again.
> Grace
>  Jonathan Daugherty <[EMAIL PROTECTED]> wrote:# Hello, I want to
input a string which is used to create file name on unix. and I want to
allow input string to consist of letters(A-Z, or a-z) and numbers(0-9) and
underscroe( _ ) within file name.
> #
> # Does anoybody know how to check the input string legal or not?
>
> # note: the following does not permit empty names.
>
> if ($input =~ /[A-Za-z0-9\_]+/) {
> # create file
> } else {
> # report error
> }
>
> --
>
> Jonathan Daugherty
> http://www.cprogrammer.org
>
>
>
>
> ---------------------------------
> Do you Yahoo!?
> HotJobs - Search new jobs daily now


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

Reply via email to