Hi guys... If you've suffered with the URL and Email validations or if you're looking for a best URL and Email validation techniques using the Java. Here is the solution for that... I've created a new class with two methods for checking the Email and URL and tested it with all kinds of real time URLs.

Validation.java

/**
 * Checks whether the given email address is valid.
 * 
 * @author SANTHOSH REDDY MANDADI
 * @since 09-Feb-2009
 * @version 1.0
 */
public class Validation
{
  /**
   * Checks whether the given email address is valid.
   * 
   * @param email represents the email address.
   * @return true if the email is valid, false otherwise.
   * @since 09-Feb-2009
   */
  public static boolean isEmail(String email)
  {
    if (email == null) {
      return false;
    }
    // Assigning the email format regular expression
    String emailPattern = "^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})";
    return email.matches(emailPattern);
  }

  /**
   * Checks whether the given URL (website address) is valid.
   * 
   * @param url represents the website address.
   * @return true if the email is valid, false otherwise.
   * @since 09-Feb-2009
   */
  public static boolean isURL(String url)
  {
    if (url == null) {
      return false;
    }
    // Assigning the url format regular expression
    String urlPattern = "^http(s{0,1})://[a-zA-Z0-9_/\\-\\.]+\\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\\&\\?\\=\\-\\.\\~\\%]*";
    return url.matches(urlPattern);
  }
}

In order to use the above class, place it in your working directory and invoke it directly through the class name Validator.isURL(url) and Validator.isEmail(email) to validate.

The above program has been tested on the platforms 1.4 and 1.5.

Click here to check out other programs that I've developed.