validate input from user for file name

Hello,

This may have been addressed already somewhere, however I am looking for the easiest/shortest way to validate a response from a user for a file name.
The file name should not have any of the following characters

~`!@#$%^&*()_-+={[}]|\:;"'<,>.?/

Further the response should not have any control characters or non printable characters.

Please advise which utility to use for this purpose. I am kind of leaning toward either a tr or sed or grep command. Please advise. Thanks.

Jerardfjay

The following function makes the work :

isValidFileName ()
{
   echo "$1" | egrep -q '^[[:alnum:]]+$'
}

filename=xxxx
if isValidFileName "$filename"
then echo "Valid"
else echo "Invalid !!"
fi

Jean-Pierre.

Jean-Pierre. Thanks for your quick response.
This code works fine except when I enter "*" for the file name, then the shell expands all of the current files within my current folder where I have the shell script running and returns that the name of the file is valid, which we know is not true. How can I overcome this? Thanks. Jerardfjay

Sorry. This code works fine. There were other checks which were causing the error and not this piece of code. Thank you.