diff --git a/core/lib/Drupal/Component/Utility/UrlHelper.php b/core/lib/Drupal/Component/Utility/UrlHelper.php
index 443673447e..cd0f1a3389 100644
--- a/core/lib/Drupal/Component/Utility/UrlHelper.php
+++ b/core/lib/Drupal/Component/Utility/UrlHelper.php
@@ -400,8 +400,14 @@ public static function isValid($url, $absolute = FALSE) {
           (?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)*      # a username or a username and password
           (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@          # combination
         )?
-        (?:
-          (?:[a-z0-9\-\.]|%[0-9a-f]{2})+                        # A domain name or a IPv4 address
+        (?:                                                     # A domain name
+          (?:[a-z0-9]
+            (?:-?(?:[a-z0-9]|%[0-9a-f]{2}))*
+            (?:\.([a-z0-9]
+              (?:-?(?:[a-z0-9]|%[0-9a-f]{2}))*
+            ))*
+          )
+          |(?:[0-9]{1,3}(?:\.[0-9]{1,3}){3})                    # or a IPv4 address
           |(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\])         # or a well formed IPv6 address
         )
         (?::[0-9]+)?                                            # Server port number (optional)
diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
index 7b9bd1c40e..a0d49a3664 100644
--- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
@@ -101,6 +101,11 @@ public function providerTestInvalidAbsolute() {
       '',
       'ex!ample.com',
       'ex%ample.com',
+      '-',
+      '-example.com',
+      'example-.com',
+      'example.-com',
+      'example.com-',
     ];
     return $this->dataEnhanceWithScheme($data);
   }
