diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index 80e1545caf..046f522a09 100644
--- a/src/wp-includes/formatting.php
+++ b/src/wp-includes/formatting.php
@@ -2948,6 +2948,57 @@ function is_email( $email, $deprecated = false ) {
 }
 
 /**
+ * Verifies that an url is valid as wordpress site url
+ * The regex check just if th protocol are http o https.
+ * In case other protocol are need to be considered valid, one has to edit the regex through the filter
+ *
+ * @param string $url      Url address to verify.
+ * @return bool            False if it is not a valid wordpress site url
+ */
+function is_valid_wordpress_url($url){
+
+    $valid_url_pattern = '~^
+            (http(s)?)://                           # protocol
+            (([\pL\pN-]+:)?([\pL\pN-]+)@)?          # basic auth
+            (
+                ([\pL\pN\pS-\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
+                    |                                                 # or
+                \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}                    # an IP address
+                    |                                                 # or
+                \[
+                    (?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25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f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
+                \]  # an IPv6 address
+            )
+            (:[0-9]+)?                              # a port (optional)
+            (?:/ (?:[\pL\pN\-._\~!$&\'()*+,;=:@]|%%[0-9A-Fa-f]{2})* )*      # a path
+        $~ixu';
+
+    /**
+     * basic check before running the regex
+     */
+    if( empty( trim($url) ) ){
+        return false;
+    }
+
+    /**
+     * Filters to edit the regex pattern for a valid url
+     *
+     * @param string $valid_url_pattern    The regex pattern to valid url against
+     */
+    $valid_url_pattern = apply_filters( 'valid_url_pattern', $valid_url_pattern );
+
+    if (!preg_match($valid_url_pattern, $url)) {
+
+        //is not a valid url
+        return false;
+    }else{
+
+        //is valid url
+        return true;
+    }
+}
+
+/**
  * Convert to ASCII from email subjects.
  *
  * @since 1.2.0
@@ -4155,27 +4206,18 @@ function sanitize_option( $option, $value ) {
 			break;
 
 		case 'siteurl':
+        case 'home':
 			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
 			if ( is_wp_error( $value ) ) {
 				$error = $value->get_error_message();
 			} else {
-				if ( preg_match( '#http(s?)://(.+)#i', $value ) ) {
-					$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.' );
-				}
-			}
-			break;
-
-		case 'home':
-			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
-			if ( is_wp_error( $value ) ) {
-				$error = $value->get_error_message();
-			} else {
-				if ( preg_match( '#http(s?)://(.+)#i', $value ) ) {
-					$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.' );
+                $value = esc_url_raw( $value );
+				if ( ! is_valid_wordpress_url( $value ) ) {
+				    if( $option == 'siteurl' ) {
+                        $error = __('The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.');
+                    } else {
+                        $error = __( 'The Site address you entered did not appear to be a valid URL. Please enter a valid URL.' );
+                    }
 				}
 			}
 			break;
diff --git a/tests/phpunit/tests/formatting/IsUrl.php b/tests/phpunit/tests/formatting/IsUrl.php
index 0432fa62da..12f54cf49b 100644
--- a/tests/phpunit/tests/formatting/IsUrl.php
+++ b/tests/phpunit/tests/formatting/IsUrl.php
@@ -3,29 +3,99 @@
 /**
  * @group formatting
  */
-class Tests_Formatting_IsEmail extends WP_UnitTestCase {
-	function test_returns_the_email_address_if_it_is_valid() {
-		$data = array(
-			"bob@example.com",
-			"phil@example.info",
-			"ace@204.32.222.14",
-			"kevin@many.subdomains.make.a.happy.man.edu"
-			);
-		foreach ( $data as $datum ) {
-			$this->assertEquals( $datum, is_email( $datum ), $datum );
-		}
+class Tests_Formatting_IsUrl extends WP_UnitTestCase {
+
+	/**
+	 * @dataProvider valid_urls_provider
+	 */
+	function test_returns_the_url_if_it_is_valid( $datum ) {
+			$this->assertTrue( is_valid_wordpress_url( $datum ), "Expected URL $datum to be a valid wordpress URL" );
+	}
+
+	/**
+	 * @dataProvider invalid_urls_provider
+	 */
+	function test_returns_false_if_given_an_invalid_url($datum) {
+			$this->assertFalse(is_valid_wordpress_url($datum), "Expected URL $datum to NOT be a valid wordpress URL");
 	}
 
-	function test_returns_false_if_given_an_invalid_email_address() {
-		$data = array(
-			"khaaaaaaaaaaaaaaan!",
-			'http://bob.example.com/',
-			"sif i'd give u it, spamer!1",
-			"com.exampleNOSPAMbob",
-			"bob@your mom"
+	public function valid_urls_provider() {
+		return array(
+				array( 'http://localhost' ),
+				array( 'http://localhost/' ),
+				array( 'https://localhost/' ),
+				array( 'http://wordpress.org' ),
+				array( 'http://wordpress.org/' ),
+				array( 'https://wordpress.org/' ),
+				array( 'http://wordpress.org:80' ),
+				array( 'http://wordpress.org:80/' ),
+				array( 'http://www.wordpress.org/' ),
+				array( 'http://www.wordpress.org' ),
+				array( 'http://foo-wordpress.org/' ),
+				array( 'http://foo.wordpress.org/hello.html' ),
+				array( 'http://very.long.domain.name.com/' ),
+				array( 'http://10.0.50.0' ),
+				array( 'http://10.0.50.0:80' ),
+				array( 'http://[::1]' ),
+				array( 'http://[::1]:80' ),
+				array( 'http://[2001:db8:85a3::8a2e:370:7334]' ),
+				array( 'http://sãopaulo.com/' ),
+				array( 'http://xn--sopaulo-xwa.com/' ),
+				array( 'http://sãopaulo.com.br/' ),
+				array( 'http://xn--sopaulo-xwa.com.br/' ),
+				array( 'http://пример.испытание/' ),
+				array( 'http://xn--e1afmkfd.xn--80akhbyknj4f/' ),
+				array( 'http://مثال.إختبار/' ),
+				array( 'http://xn--mgbh0fb.xn--kgbechtv/' ),
+				array( 'http://例子.测试/' ),
+				array( 'http://xn--fsqu00a.xn--0zwm56d/' ),
+				array( 'http://例子.測試/' ),
+				array( 'http://xn--fsqu00a.xn--g6w251d/' ),
+				array( 'http://例え.テスト/' ),
+				array( 'http://xn--r8jz45g.xn--zckzah/' ),
+				array( 'http://مثال.آزمایشی/' ),
+				array( 'http://xn--mgbh0fb.xn--hgbk6aj7f53bba/' ),
+				array( 'http://실례.테스트/' ),
+				array( 'http://xn--9n2bp8q.xn--9t4b11yi5a/' ),
+				array( 'http://العربية.idn.icann.org/' ),
+				array( 'http://xn--ogb.idn.icann.org/' ),
+				array( 'http://xn--e1afmkfd.xn--80akhbyknj4f.xn--e1afmkfd/' ),
+				array( 'http://xn--espaa-rta.xn--ca-ol-fsay5a/' ),
+				array( 'http://xn--d1abbgf6aiiy.xn--p1ai/' ),
+				array( 'http://☎.com/' ),
+				array( 'http://username:password@wordpress.org' ),
+				array( 'http://user-name@wordpress.org' )
 			);
-		foreach ($data as $datum) {
-			$this->assertFalse(is_email($datum), $datum);
-		}
+	}
+
+	public function invalid_urls_provider() {
+		return array(
+				array( '' ),
+				array( 'http;//' ),
+				array( 'wordpress.org' ),
+				array( 'http://wordpress .org' ),
+				array( 'http://wordpress*.org' ),
+				array( 'http://wordpress?.org' ),
+				array( 'http://word_press.org' ),
+				array( 'http://wordpress.org?something' ),
+				array( 'http://wordpress.org?' ),
+				array( 'http://wordpress.org/?something' ),
+				array( 'http://wordpress.org#something' ),
+				array( 'http://wordpress.org/#something' ),
+				array( 'http://::1' ),
+				array( 'ftp://[::1]' ),
+				array( 'http://wordpress.org?' ),
+				array( 'http://wordpress.org?query=1' ),
+				array( 'http://wordpress.org/?query=1' ),
+				array( 'http://wordpress.org#' ),
+				array( 'http://wordpress.org#fragment' ),
+				array( 'http://wordpress.org/#fragment' ),
+				array( 'http://wordpress.org/#one_more%20test' ),
+				array( 'mailto:nobody@wordpress.org?subject=hi' ),
+				array( 'ftp://wordpress.org/' ),
+				array( 'javascript:alert(1)' ),
+				array( 'unknown://something.out-there' ),
+				array( 'http://hello.☎/' ),
+		);
 	}
 }
