diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
index 1b2d29dc3b..b06ea4242e 100644
--- src/wp-includes/class-wp-customize-manager.php
+++ src/wp-includes/class-wp-customize-manager.php
@@ -480,7 +480,7 @@ final class WP_Customize_Manager {
 			return;
 		}
 
-		if ( ! preg_match( '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/', $this->_changeset_uuid ) ) {
+		if ( ! wp_is_valid_uuid( $this->_changeset_uuid ) ) {
 			$this->wp_die( -1, __( 'Invalid changeset UUID' ) );
 		}
 
diff --git src/wp-includes/functions.php src/wp-includes/functions.php
index 3923ca92ec..650f1f6ebb 100644
--- src/wp-includes/functions.php
+++ src/wp-includes/functions.php
@@ -5610,6 +5610,34 @@ function wp_generate_uuid4() {
 }
 
 /**
+ * Validate if a string is a valid UUID.
+ *
+ * @param string $uuid
+ *
+ * @param int $version Specify which version of UUID we should check against.
+ *
+ * @return bool The string is a valid UUID V4 or false on failure.
+ */
+function wp_is_valid_uuid( $uuid, $version = null ) {
+
+    if ( ! is_string( $uuid ) ) {
+        return false;
+    }
+
+	$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
+
+	if ( isset( $version ) ) {
+	    if ( 4 !== $version ) {
+		    _doing_it_wrong( __FUNCTION__, __( 'Only UUID V4 is supported at this time.' ) );
+		    return false;
+        }
+        $regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/';
+    }
+
+	return (bool) preg_match( $regex, $uuid );
+}
+
+/**
  * Get last changed date for the specified cache group.
  *
  * @since 4.7.0
diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php
index 8932bc63f7..ebab1064a6 100644
--- tests/phpunit/tests/functions.php
+++ tests/phpunit/tests/functions.php
@@ -891,11 +891,59 @@ class Tests_Functions extends WP_UnitTestCase {
 		$uuids = array();
 		for ( $i = 0; $i < 20; $i += 1 ) {
 			$uuid = wp_generate_uuid4();
-			$this->assertRegExp( '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $uuid );
+			$this->assertTrue( wp_is_valid_uuid( $uuid, 4 ) );
 			$uuids[] = $uuid;
 		}
 
 		$unique_uuids = array_unique( $uuids );
 		$this->assertEquals( $uuids, $unique_uuids );
 	}
+
+	/**
+	 * Tests wp_is_valid_uuid().
+	 *
+	 * @covers ::wp_is_valid_uuid
+	 * @ticket 39778
+	 */
+	function test_wp_is_valid_uuid() {
+		$uuids = array(
+			'27fe2421-780c-44c5-b39b-fff753092b55',
+			'b7c7713a-4ee9-45a1-87ed-944a90390fc7',
+			'fbedbe35-7bf5-49cc-a5ac-0343bd94360a',
+			'4c58e67e-123b-4290-a41c-5eeb6970fa3e',
+			'f54f5b78-e414-4637-84a9-a6cdc94a1beb',
+			'd1c533ac-abcf-44b6-9b0e-6477d2c91b09',
+			'7fcd683f-e5fd-454a-a8b9-ed15068830da',
+			'7962c750-e58c-470a-af0d-ec1eae453ff2',
+			'a59878ce-9a67-4493-8ca0-a756b52804b3',
+			'6faa519d-1e13-4415-bd6f-905ae3689d1d',
+		);
+
+		foreach ( $uuids as $uuid ) {
+			$this->assertTrue( wp_is_valid_uuid( $uuid, 4 ) );
+		}
+
+		$uuids = array(
+			'a19d5192-ea41-11e6-b006-92361f002671',
+			'a19d5192-ea41-21e6-b006-92361f002671',
+			'a19d5192-ea41-31e6-b006-92361f002671',
+		);
+
+		foreach ( $uuids as $uuid ) {
+			$this->assertTrue( wp_is_valid_uuid( $uuid ) );
+		}
+
+		$invalid_uuids = array(
+			'a19d5192-ea41-41e6-b006',
+			'this-is-not-valid',
+			1234,
+			true,
+			[],
+		);
+
+		foreach ( $invalid_uuids as $invalid_uuid ) {
+			$this->assertFalse( wp_is_valid_uuid( $invalid_uuid, 4 ) );
+			$this->assertFalse( wp_is_valid_uuid( $invalid_uuid ) );
+		}
+	}
 }
