Java Regex URL Validate isUrlFile(String filePath)

Here you can find the source of isUrlFile(String filePath)

Description

check if it is a Url

License

Open Source License

Parameter

Parameter Description
filePath a parameter

Return

Url name if it is a url otherwise null

Declaration

public static boolean isUrlFile(String filePath) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/* w  w w . ja  v  a2s.c  o m*/
     * check if it is a Url
     * 
     * @param filePath
     * @return Url name if it is a url otherwise null
     */
    public static boolean isUrlFile(String filePath) {

        String urlPattern = "((https?|ftp):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
        Pattern p = Pattern.compile(urlPattern, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(filePath);
        if (m.find()) {
            return true;
        }

        return false;
    }
}

Related

  1. isURL(String url)
  2. isUrl(String url)
  3. isURL(String url)
  4. isUrl(String x)
  5. isUrlAddress(String text)
  6. isUrlWithUserInfo(String str)
  7. isUrn(String value)