Trim search box fields

We are having an issue where users are copying data from another source like excel and pasting it into the search but there is an extra space at the end of the string, so the search results show 0 results. For example a user will paste '[email protected] ' and nothing will show even though '[email protected]' is in the database. Is there any way to automatically trim a search field?