diff --git a/entityreference.module b/entityreference.module
index 18b329e..166c4ac 100644
--- a/entityreference.module
+++ b/entityreference.module
@@ -713,7 +713,7 @@ function _entityreference_autocomplete_validate($element, &$form_state, $form) {
   if (!empty($element['#value'])) {
     // Take "label (entity id)', match the id from parenthesis.
     if (preg_match("/.+\((\d+)\)/", $element['#value'], $matches)) {
-      $value = $matches[1];
+      $value = (int) $matches[1];
     }
   }
 
@@ -731,7 +731,7 @@ function _entityreference_autocomplete_tags_validate($element, &$form_state, $fo
       // Take "label (entity id)', match the id from parenthesis.
       if (preg_match("/.+\((\d+)\)/", $entity, $matches)) {
         $value[] = array(
-          'target_id' => $matches[1],
+          'target_id' => (int) $matches[1],
         );
       }
     }
