hook_field_attach_presave not saving - user profile field EDIT: As per a suggestion below, I tried using hook_field_presave, but couldn't access any parameters of the field. I then tried hook_field_attach_presave, but my alterations aren't being saved. My current module code is :

function module_field_attach_presave($entity_type, $entity) {
  $field = $entity-&gt;field_user_location;
  $locality = $field['und'][0]['locality'];
  $locality = ucwords(strtolower($locality));
  dpm($locality);
  }


The transformation is present when Locality prints out via dpm, but the transformation is not saved to the field itself. Any idea why?

ORIGINAL: I'm using an AddressField field in my user profiles, but I'd like to make sure that the cities that users enter are correctly capitalized. How can I do this? 

I'm assuming it's some implementation of str_replace, but I don't know what to do with it.
You'll need to implement hook_field_presave(). You can find out from the parameters passed in if it's being invoked for an address field saved to a user account and do the necessary transformation on the 'locality' of the address field value in the $items array.