Java URL Value Check isUrl(String s)

Here you can find the source of isUrl(String s)

Description

is Url

License

Apache License

Declaration

private static boolean isUrl(String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;

public class Main {
    protected static Pattern scheme = Pattern
            .compile("^[a-zA-Z][A-Za-z0-9+.-]*:\\/\\/");

    private static boolean isUrl(String s) {
        s = s.trim();//Trim whitespace
        boolean missingScheme = false;
        if (!scheme.matcher(s).find()) {
            //No scheme specified. 
            //if (s.indexOf('\\') > -1) return false; //It means we have a windows path.

            //s = "http://" + s;
            //missingScheme = true;
            return false; //Don't try to help. If they forgot the http://, consider it a program
        }/*w  ww  .j  ava  2s  . c o  m*/
        try {
            URL u = new URL(s);
            //if (missingScheme && !TokenUtils.fastMatches(regex, u.getHost()))
            return true;
        } catch (MalformedURLException e) {
            return false;
        }
    }
}

Related

  1. isUrl(String input)
  2. isURL(String name)
  3. isURL(String possibleURL)
  4. isUrl(String resourceLocation)
  5. isUrl(String resourceLocation)
  6. isUrl(String s)
  7. isURL(String str)
  8. isURL(String token)
  9. isUrl(String value)