Here you can find the source of isValidEmail(final String email)
Indicates wether a given string is a valid email address
Email format is :
Parameter | Description |
---|---|
the string to validate |
true
if the string is a valid email address, false
otherwise
public static boolean isValidEmail(final String email)
//package com.java2s; // under the terms of the GNU General Public License as published by the import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /**//from ww w. j a v a2 s.c o m * <p> * Indicates wether a given string is a valid email address * </p> * <p> * Email format is : * <li>starts with A-Za-z or '-'</li> * <li>then has any number of A-Za-z (can be zero)</li> * <li>has any number of '.' followed by one of more characters</li> * <li>has an '@'</li> * <li>has any number of A-Za-z0-9</li> * <li>has a '.' then 2 to 4 A-Za-z</li> * </p> * * @param email the string to validate * @return <code>true</code> if the string is a valid email address, * <code>false</code> otherwise */ public static boolean isValidEmail(final String email) { final String expression = "^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")" + "@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$"; final Pattern pattern = Pattern.compile(expression); final Matcher matcher = pattern.matcher(email); return matcher.matches(); } }