How to trim text fields entered in the node automatically
To correct all those values entered into the database already, I'd suggest doing a mysql trim on those values and resetting them. Make sure you backup the tables first of course, but something like this should do it (if your field name is field_text_test):

UPDATE field_data_field_text_test SET field_text_test_value = TRIM(field_text_test_value);
UPDATE field_revision_field_text_test SET field_text_test_value = TRIM(field_text_test_value);


After you've run those statements, do a flush all caches on your drupal site.

And then to avoid this happening again, you could use the Form API Validation module which adds a trim filter on fields.