in reply to Checking input

perlre should do the trick
quick answer is
$input =~ /^\w+$/; $input =~ /^\d+$/;

--
Jaap Karssenberg || Pardus (Larus)? <pardus@cpan.org>
>>>> Zoidberg: So many memories, so many strange fluids gushing out of patients' bodies.... <<<<

Replies are listed 'Best First'.
Re: Re: Checking input
by hardburn (Abbot) on Feb 25, 2003 at 17:09 UTC

    He also needs to check for '-', which \w doesn't do. That first regex should be /^[\w-]+$/

    ----
    Reinvent a rounder wheel.

    Note: All code is untested, unless otherwise stated

      It looks to me like the character class is the beginning of a range (the [\w-] bit). I know it isn't, and I know Perl has no problems with this (I just ran a test script to verify that).

      But wouldn't it be a little clearer to write the character class as either [-\w] or [\w\-] ? This is really just a formatting question more than anything else.

        No - your usage is buggy. Consider perl -e 'print join "\n", qr/[\w\-]/,qr/[\w-]/,""'. Don't "escape" the hyphen because that's not what happens.


        Seeking Green geeks in Minnesota