Trimming field values

Trimming field values

How can I make a form automatically trim the leading and trailing spaces of a text-string?
I wanted to do this to avoid duplicate entries.

Thanks.