On 12 Jun 2001 17:45:16 +0200, Jos Boumans wrote:
> try this:
>
> unless (/^[-\.\w]+$/) { print "you cheater!" }
>
> this will check if from beginning to end of $_ it contains - . (not even sure
> you need to \ the . ) or any word character (a-z A-Z and _ )
>
> the ^ says to start at the beginning of the string... the $ says to read till
> end of line...
<snip />
This regexp is a little to verbose (and wrong since - is not escaped).
Since we want a failure if any character fails to match "a-z", "A-Z",
"0-9", "_", "-", "." we don't need to test that the whole string is
correct, only that any character in it is wrong:
if (/[^\w.\-]/) { print "you cheater!" }
However, if you wanted to limit the string to $x characters you might be
better off testing like this:
unless (/^[\w.\-]{1,$x}$/) { print "you cheater!" }
--
Today is Pungenday, the 17th day of Confusion in the YOLD 3167
Umlaut Zebra über alles!