I have a regexp to validate file names. Here is it:
/[0-9a-zA-Z\\^\\&\\\'\\@\\{\\}\\[\\]\\,\\$\\=\\!\\-\\#\\(\\)\\.\\%\\+\\~\\_ ]+$/
It
You need to add a starting anchor:
/^[0-9a-zA-Z ... ]+$/
This tells the engine to match from the start of the input all the way to the end of the input, whereas for your original expression it only needs to match at the end of the input.