Android URL Parse checkStringIsUrl(String input)

Here you can find the source of checkStringIsUrl(String input)

Description

check String Is Url

Declaration

public static boolean checkStringIsUrl(String input) 

Method Source Code

//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static boolean checkStringIsUrl(String input) {
        if (input == null)
            return false;
        if (input.indexOf("tel://") == 0) {
            return true;
        }/*  www .jav a  2 s. co m*/
        if (input.indexOf("mailto:") == 0 && input.contains("@")) {
            return true;
        }
        if (input.indexOf("wtai://") == 0) {
            return true;
        }
        Pattern pattern = Pattern
                .compile(
                        "(^((https|http|ftp|rtsp|mms)?://)"
                                + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"
                                + "(([0-9]{1,3}\\.){3}[0-9]{1,3}"
                                + "|"
                                + "([0-9a-z_!~*'()-]+\\.)*"
                                + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\\."
                                + "[a-z]{2,6})"
                                + "(:[0-9]{1,4})?"
                                + "((/?)|"
                                + "(/[0-9a-z\\u4e00-\\u9fa5_!~*'().;?:@&=+$,%#-/]+)+/?)$)|(^file://*)",
                        Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(input.trim());
        if (matcher.find()) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. getParentUrl(String url)
  2. getRecentMediaUrl(String tag)
  3. getStringFromUrl(String url)
  4. getUrlContent(String urlStr)
  5. getUrlQueryParameters(final String url)
  6. hostFromUrl(String url)
  7. hasParameter(String url, String name)
  8. validateUrl(String url)