Here you can find the source of isValidEmail(String eMailAddress)
Parameter | Description |
---|---|
eMailAddress | a parameter |
public static boolean isValidEmail(String eMailAddress)
//package com.java2s; /****************************************************************************** * Copyright (C) Devamatre Technologies 2009 * //w w w . j a v a 2s . c o m * This code is licensed to Devamatre under one or more contributor license * agreements. The reproduction, transmission or use of this code or the * snippet is not permitted without prior express written consent of Devamatre. * * Unless required by applicable law or agreed to in writing, software * distributed under the license is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied and the * offenders will be liable for any damages. All rights, including but not * limited to rights created by patent grant or registration of a utility model * or design, are reserved. Technical specifications and features are binding * only insofar as they are specifically and expressly agreed upon in a written * contract. * * You may obtain a copy of the License for more details at: * http://www.devamatre.com/licenses/license.txt. * * Devamatre reserves the right to modify the technical specifications and or * features without any prior notice. *****************************************************************************/ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static String VALID_EMAIL_EXPRESSION = "\\b(^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z0-9]{2,})|(\\.[A-Za-z0-9]{2,}\\.[A-Za-z0-9]{2,}))$)\\b"; /** * Returns true if a valid email address is passed. The email address * criteria is: This means an email can start with any combination of * letters and numbers that is followed by any number of periods and letters * and numbers. It must have a @ character followed by a valid host name. * * Expression Pattern Used: * "\\b(^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\\.[A-Za-z0-9- * ]+)*((\\.[A-Za-z0-9]{2,})|(\\.[A-Za-z0-9]{2,}\\.[A-Za-z0-9]{2,}))$)\\b" * * @param eMailAddress * @return */ public static boolean isValidEmail(String eMailAddress) { Pattern pattern = Pattern.compile(VALID_EMAIL_EXPRESSION); Matcher matcher = pattern.matcher(VALID_EMAIL_EXPRESSION); return matcher.find(); } }