Java URL Value Check isEMailAddress(URL url)

Here you can find the source of isEMailAddress(URL url)

Description

is E Mail Address

License

LGPL

Declaration

public static boolean isEMailAddress(URL url) 

Method Source Code


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

import java.net.URL;

public class Main {
    public static boolean isEMailAddress(URL url) {
        boolean result = true;

        String urlString = url.toString();

        if (url.getHost() != null && !url.getHost().trim().equals("")) {
            result = false;//from  w  w w  .j av  a 2s.  co  m
        }
        if (url.getPort() != -1) {
            result = false;
        }

        int pos = urlString.indexOf('@');
        if (pos == -1) {
            result = false;
        } else {
            // check for a second '@' sign
            if (urlString.indexOf('@', pos + 1) != -1) {
                return false;
            }
        }

        // check if the host is possible
        if (pos > (urlString.length() - 6)) {
            result = false;
        }

        return result;

    }
}

Related

  1. is200(final String url)
  2. is404(URL url)
  3. isAddressReachable(String url, int timeout)
  4. isAValidURL(String url)
  5. isCompressed(HttpURLConnection connection)
  6. isFile(final URL url)
  7. isFile(final URL url)
  8. isFile(URL url)
  9. isFile(URL url)