Android String to URL Convert isValidUrl(String url)

Here you can find the source of isValidUrl(String url)

Description

is Valid Url

Declaration

public static boolean isValidUrl(String url) 

Method Source Code

//package com.java2s;
import android.text.TextUtils;

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

public class Main {
    public static boolean isValidUrl(String url) {
        if (isBlank(url))
            return false;

        String strPattern = "^(http|https)://(.+)/(.+)([.]+)(.+)$";
        Pattern p = Pattern.compile(strPattern);
        Matcher m = p.matcher(url);
        return m.matches();
    }/*from   ww  w  .  jav  a2  s  .  c  o m*/

    /**
     * Whether the String is null, zero-length and does contain only whitespace
     */
    public static boolean isBlank(String text) {
        if (isEmpty(text))
            return true;
        for (int i = 0; i < text.length(); i++) {
            if (!Character.isWhitespace(text.charAt(i)))
                return false;
        }
        return true;
    }

    /**
     * Whether the given string is null or zero-length
     */
    public static boolean isEmpty(String text) {
        return TextUtils.isEmpty(text);
    }
}

Related

  1. isImageUrl(String imgUrl)
  2. getBaseUrl(String pageUrl)
  3. getYoutubeId(String url)
  4. preUrl(String url)
  5. TruncateUrlPage(String strURL)
  6. imageUrl_2_ImageName(String imageUrl)
  7. extractUrls(String text)
  8. isUrlValid(String str, boolean isCaseSensitve)