Java Email Validate isEmailValid(String email)

Here you can find the source of isEmailValid(String email)

Description

isEmailValid: Validate email address using Java reg ex.

License

Open Source License

Parameter

Parameter Description
email String. Email address to validate

Return

boolean: true if email address is valid, false otherwise.

Declaration

public static boolean isEmailValid(String email) 

Method Source Code


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

import java.util.regex.*;

public class Main {
    /** isEmailValid: Validate email address using Java reg ex.
     * This method checks if the input string is a valid email address.
     * @param email String. Email address to validate
     * @return boolean: true if email address is valid, false otherwise.
     *//*  ww  w.j av  a  2 s .c  om*/
    public static boolean isEmailValid(String email) {
        boolean isValid = false;

        //Initialize reg ex for email.
        String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
        CharSequence inputStr = email;
        //Make the comparison case-insensitive.
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }
}

Related

  1. isEmailer(String email)
  2. isEmailFormatValid(String emailAddress)
  3. isEmailValid(String address)
  4. isEmailValid(String email)
  5. isEmailValid(String email)
  6. isEmailValid(String emailAddress)
  7. isLegarEmail(String email)
  8. isMail(String email)
  9. isMobilesOrEmail(String str)