in reply to Re: Regular expression to check for invalid file name characters
in thread Regular expression to check for invalid file name characters

Maybe a character class of what is allowed would be a better approach, users can be very inventive :)

sub is_valid_name { $_[0] =~ m{[a-zA-Z0-9_ ]} }

Update: OOps, still learning ..., a negated character class.

sub is_valid_name { $_[0] !~ m{[^a-zA-Z0-9_ ]} }
Update2: JavaFan is right, this is not the right way to do it.

Update3: ... and I need my salary and don't want to upset the rest of the world ;)

Replies are listed 'Best First'.
Re^3: Regular expression to check for invalid file name characters
by JavaFan (Canon) on Feb 22, 2010 at 13:02 UTC
    So, no Unicode or accented characters or even dots or hyphens? Your fellow Chinese, Korean, French, Swedish, Indian and Arabic Perlmonks will not be happy with that. Neither will your fellow Perl or C coders. (Nope, can't have Module.pm. Nor main.c. salary_run_2010-02? No payment for you!)

    Sometimes, it's just easier to list what you want to exclude.