I use the references module. I have a custom form, into which I capture names into a user reference field via the autocomplete widget. So, on the form, if a user types Joe, the following appears in the input box:

	Joe [uid: 5]

Now, I do not want insert this into my database as it is because my 'Name' field is expecting just the uid. So I need to pass '5' to the database, not the string 'Joe [uid: 5]'.

To accomplish this, before I write my record to the database I pass the string 'Joe [uid: 5]' through this code:

	// * Search for match (integer) to regular expression and put in $integer.
	preg_match_all('!\d+!', $form_state['values']['name'], $integer);
	
	// * Return string representation of array elements.
	$name_uid = implode(' ', $integer[0]);

$name_uid now contains '5' and is ready to be inserted. Is there an existing function that already does this? or does anyone have a better way?

Thanks