@Test public void testInvalidAddresses() { for (String address : INVALID_ADDRESSES) { if (EmailValidator.validateEmailAddressByRegex(address)) { Assert.fail("Address should be invalid: " + address); } } }
public static boolean validateEmailAddressByRegex(String email) { String[] split = email.split("@"); if (split.length != 2 || split[0].length() > MAX_LENGTH_LOCAL_PART || split[1].length() > MAX_LENGTH_DOMAIN_PART) { return false; } return PATTERN_LOCAL_PART.matcher(split[0]).matches() && PATTERN_DOMAIN_PART.matcher(split[1]).matches(); }
EmailValidator { public static boolean validateEmailAddressByRegex(String email) { String[] split = email.split("@"); if (split.length != 2 || split[0].length() > MAX_LENGTH_LOCAL_PART || split[1].length() > MAX_LENGTH_DOMAIN_PART) { return false; } return PATTERN_LOCAL_PART.matcher(split[0]).matches() && PATTERN_DOMAIN_PART.matcher(split[1]).matches(); } }
EmailValidator { public static boolean validateEmailAddressByRegex(String email) { String[] split = email.split("@"); if (split.length != 2 || split[0].length() > MAX_LENGTH_LOCAL_PART || split[1].length() > MAX_LENGTH_DOMAIN_PART) { return false; } return PATTERN_LOCAL_PART.matcher(split[0]).matches() && PATTERN_DOMAIN_PART.matcher(split[1]).matches(); } private  EmailValidator(); }
EmailValidator { public static boolean validateEmailAddressByRegex(String email) { String[] split = email.split("@"); if (split.length != 2 || split[0].length() > MAX_LENGTH_LOCAL_PART || split[1].length() > MAX_LENGTH_DOMAIN_PART) { return false; } return PATTERN_LOCAL_PART.matcher(split[0]).matches() && PATTERN_DOMAIN_PART.matcher(split[1]).matches(); } private  EmailValidator(); static boolean validateEmailAddressByRegex(String email); }
EmailValidator { public static boolean validateEmailAddressByRegex(String email) { String[] split = email.split("@"); if (split.length != 2 || split[0].length() > MAX_LENGTH_LOCAL_PART || split[1].length() > MAX_LENGTH_DOMAIN_PART) { return false; } return PATTERN_LOCAL_PART.matcher(split[0]).matches() && PATTERN_DOMAIN_PART.matcher(split[1]).matches(); } private  EmailValidator(); static boolean validateEmailAddressByRegex(String email); static final int MAX_LENGTH_LOCAL_PART; static final int MAX_LENGTH_DOMAIN_PART; static final int MAX_SAFE_LENGTH_LOCAL_PART; }