hi
your regular expression is only checking the start not the ending of the string.
try add $ at the end.
^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)$
it will remove chance of illegal characters at the end.
if you want to check for specific file formats add the formats as below
^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx)$