Here you can find the source of isValid(String url)
public static boolean isValid(String url)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012-2016 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * // w w w.ja v a 2s .c o m * Contributors: * Red Hat, Inc. - initial API and implementation ******************************************************************************/ import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.regex.Pattern; public class Main { private static final Pattern SIMPLE_URL_PATTERN = Pattern .compile("(\\w+://)(.+@)*([\\w\\d\\.]+)(:[\\d]+){0,1}/*(.*)"); public static boolean isValid(String url) { // Test via regex first. If passes then check via new URL(url) and URI(url) which are slower if (SIMPLE_URL_PATTERN.matcher(url).matches()) { try { new URI(url); new URL(url); } catch (MalformedURLException | URISyntaxException e) { return false; } return true; } return false; } }