diff --git a/app/code/Magento/Customer/Setup/UpgradeData.php b/app/code/Magento/Customer/Setup/UpgradeData.php
index b5aba18a92f2871b442393246cc7d0dab78dddeb..0ad36b1d6d11c35f55f2ebc15d05a8a36cd60ac1 100644
--- a/app/code/Magento/Customer/Setup/UpgradeData.php
+++ b/app/code/Magento/Customer/Setup/UpgradeData.php
@@ -159,6 +159,10 @@ class UpgradeData implements UpgradeDataInterface
             $this->upgradeVersionTwoZeroTwelve($customerSetup);
         }
 
+        if (version_compare($context->getVersion(), '2.0.13', '<')) {
+            $this->upgradeVersionTwoZeroThirteen($customerSetup);
+        }
+
         $indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
         $indexer->reindexAll();
         $this->eavConfig->clear();
@@ -663,4 +667,36 @@ class UpgradeData implements UpgradeDataInterface
             ['path = ?' => \Magento\Customer\Model\Customer::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD]
         );
     }
+
+    /**
+     * @param CustomerSetup $customerSetup
+     */
+    private function upgradeVersionTwoZeroThirteen(CustomerSetup $customerSetup)
+    {
+        $entityAttributes = [
+            'customer_address' => [
+                'firstname' => [
+                    'input_filter' => 'trim'
+                ],
+                'lastname' => [
+                    'input_filter' => 'trim'
+                ],
+                'middlename' => [
+                    'input_filter' => 'trim'
+                ],
+            ],
+            'customer' => [
+                'firstname' => [
+                    'input_filter' => 'trim'
+                ],
+                'lastname' => [
+                    'input_filter' => 'trim'
+                ],
+                'middlename' => [
+                    'input_filter' => 'trim'
+                ],
+            ],
+        ];
+        $this->upgradeAttributes($entityAttributes, $customerSetup);
+    }
 }
diff --git a/app/code/Magento/Customer/etc/module.xml b/app/code/Magento/Customer/etc/module.xml
index 3f0d42b12649ae4e096808e126566498289ce19a..2dfe561d0da8fb8afb17db8e8ddd24f96938acbf 100644
--- a/app/code/Magento/Customer/etc/module.xml
+++ b/app/code/Magento/Customer/etc/module.xml
@@ -6,7 +6,7 @@
  */
 -->
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
-    <module name="Magento_Customer" setup_version="2.0.12">
+    <module name="Magento_Customer" setup_version="2.0.13">
         <sequence>
             <module name="Magento_Eav"/>
             <module name="Magento_Directory"/>
diff --git a/dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php b/dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php
index 4ee936f83f537c0940f04fb2dae19680ae8d2736..f2632aa1481e4752e47e2af03ace6e51660c2a97 100644
--- a/dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php
@@ -63,7 +63,7 @@ class CustomerMetadataTest extends WebapiAbstract
                 Customer::FIRSTNAME,
                 [
                     AttributeMetadata::FRONTEND_INPUT   => 'text',
-                    AttributeMetadata::INPUT_FILTER     => '',
+                    AttributeMetadata::INPUT_FILTER     => 'trim',
                     AttributeMetadata::STORE_LABEL      => 'First Name',
                     AttributeMetadata::MULTILINE_COUNT  => 0,
                     AttributeMetadata::VALIDATION_RULES => [
diff --git a/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php b/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php
new file mode 100644
index 0000000000000000000000000000000000000000..0dbbcf6dbf8d056902f8be9193c2b7b0ed65d363
--- /dev/null
+++ b/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Copyright © Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+/**
+ * Form Input/Output Trim Filter
+ *
+ * @author      Magento Core Team <core@magentocommerce.com>
+ */
+namespace Magento\Framework\Data\Form\Filter;
+
+class Trim implements \Magento\Framework\Data\Form\Filter\FilterInterface
+{
+    /**
+     * Returns the result of filtering $value
+     *
+     * @param string $value
+     * @return string
+     */
+    public function inputFilter($value)
+    {
+        return trim($value, ' ');
+    }
+
+    /**
+     * Returns the result of filtering $value
+     *
+     * @param string $value
+     * @return string
+     */
+    public function outputFilter($value)
+    {
+        return $value;
+    }
+}