You could use negative lookarounds at the beginning and end of the pattern:
^(?![ ])[0-9pqw+*# ().-]*(?<![ ])$
Note that the brackets are not necessary but aid readability. Neither are any of your escapes (as long as you put the -
at the end).