@Test public void validate() { Assert.assertThat(invokeValidator("test@example.com"), is(true)); Assert.assertThat(invokeValidator("test.2@ex.mple.co"), is(true)); Assert.assertThat(invokeValidator("te@ex.co"), is(true)); Assert.assertThat(invokeValidator("@ex.co"), is(false)); Assert.assertThat(invokeValidator("test@example"), is(false)); Assert.assertThat(invokeValidator("test@.com"), is(false)); }
@Override public void validate(Object o, Errors errors) { String address = (String) o; address = address.trim(); if (!address.matches("^[\\w\\.-]+@([\\w-]+\\.)+[\\w-]{2,4}$")) { errors.rejectValue(null, "Invalid address format"); } }
EmailAddressValidator implements Validator { @Override public void validate(Object o, Errors errors) { String address = (String) o; address = address.trim(); if (!address.matches("^[\\w\\.-]+@([\\w-]+\\.)+[\\w-]{2,4}$")) { errors.rejectValue(null, "Invalid address format"); } } }
EmailAddressValidator implements Validator { @Override public void validate(Object o, Errors errors) { String address = (String) o; address = address.trim(); if (!address.matches("^[\\w\\.-]+@([\\w-]+\\.)+[\\w-]{2,4}$")) { errors.rejectValue(null, "Invalid address format"); } }  }
EmailAddressValidator implements Validator { @Override public void validate(Object o, Errors errors) { String address = (String) o; address = address.trim(); if (!address.matches("^[\\w\\.-]+@([\\w-]+\\.)+[\\w-]{2,4}$")) { errors.rejectValue(null, "Invalid address format"); } }  @Override boolean supports(Class<?> clazz); @Override void validate(Object o, Errors errors); }
EmailAddressValidator implements Validator { @Override public void validate(Object o, Errors errors) { String address = (String) o; address = address.trim(); if (!address.matches("^[\\w\\.-]+@([\\w-]+\\.)+[\\w-]{2,4}$")) { errors.rejectValue(null, "Invalid address format"); } }  @Override boolean supports(Class<?> clazz); @Override void validate(Object o, Errors errors);  }