Java Regex URL Validate isUrl(String url)

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

Description

is Url

License

Open Source License

Declaration

public static boolean isUrl(String url) 

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 {
    private static Pattern urlExpression = Pattern
            .compile("^((http|https|ftp)\\://)?([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)*"
                    + "((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}"
                    + "[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]"
                    + "{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.(com|de|edu|gov|int|mil|net|"
                    + "org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\\:[0-9]+)*(/($|[a-zA-Z0-9\\.\\,\\?\\'\\\\\\+&%\\$#\\=~_\\-]+))*$");

    public static boolean isUrl(String url) {
        Matcher matcher = urlExpression.matcher(url);
        return matcher.matches();
    }//ww  w  .ja va 2 s .co  m
}

Related

  1. isUrl(String s)
  2. IsUrl(String str)
  3. isUrl(String test)
  4. isUrl(String text)
  5. isURL(String url)
  6. isURL(String url)
  7. isUrl(String x)
  8. isUrlAddress(String text)
  9. isUrlFile(String filePath)