diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
index 4e8f63d..38c8a28 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -4159,7 +4159,7 @@ function sanitize_option( $option, $value ) {
 			if ( is_wp_error( $value ) ) {
 				$error = $value->get_error_message();
 			} else {
-				if ( preg_match( '#http(s?)://(.+)#i', $value ) ) {
+				if ( preg_match( '#http(s?)://(.+)#i', $value ) && filter_var($value, FILTER_VALIDATE_URL) !== false) {
 					$value = esc_url_raw( $value );
 				} else {
 					$error = __( 'The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.' );
@@ -4172,7 +4172,7 @@ function sanitize_option( $option, $value ) {
 			if ( is_wp_error( $value ) ) {
 				$error = $value->get_error_message();
 			} else {
-				if ( preg_match( '#http(s?)://(.+)#i', $value ) ) {
+				if ( preg_match( '#http(s?)://(.+)#i', $value ) && filter_var($value, FILTER_VALIDATE_URL) !== false) {
 					$value = esc_url_raw( $value );
 				} else {
 					$error = __( 'The Site address you entered did not appear to be a valid URL. Please enter a valid URL.' );
