Here you can find the source of isValidEmail(String emailAddress)
Parameter | Description |
---|---|
emailAddress | the input string for test |
public static boolean isValidEmail(String emailAddress)
//package com.java2s; /*/*from w w w . ja va 2 s . co m*/ * Copyright (c) 2007 IJO Technologies Ltd. * www.ijotechnologies.com * All rights reserved. * * This software is the confidential and proprietary information of * IJO Technologies ("Confidential Information"). * You shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement you * entered into with IJO Technologies. */ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final String EMAIL_REGULAR_EXPRESSION = "^[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$"; /** * This method is used to test whether a string is a valid email address or not * * @param emailAddress the input string for test * @return if the email address is valid return true,otherwise return false. */ public static boolean isValidEmail(String emailAddress) { if (emailAddress == null) { return false; } Pattern p = Pattern.compile(EMAIL_REGULAR_EXPRESSION); Matcher m = p.matcher(emailAddress); return m.matches(); } }