@Test public void testValidacaoCepCorreto() { CepValidator validator = new CepValidator(); Assert.assertTrue(validator.isValid("40290280", null)); Assert.assertTrue(validator.isValid("40290281", null)); Assert.assertTrue(validator.isValid("40.290-280", null)); Assert.assertTrue(validator.isValid("40290-280", null)); }
@Override public boolean isValid(String cep, final ConstraintValidatorContext context) { boolean result = false; if ( cep == null || "".equals(cep) ) { result = true; } else { Pattern pattern = Pattern.compile("^(([0-9]{2}\\.[0-9]{3}-[0-9]{3})|([0-9]{2}[0-9]{3}-[0-9]{3})|([0-9]{8}))$"); Matcher matcher = pattern.matcher(cep); result = matcher.find(); } return result; }
CepValidator implements ConstraintValidator<Cep, String> { @Override public boolean isValid(String cep, final ConstraintValidatorContext context) { boolean result = false; if ( cep == null || "".equals(cep) ) { result = true; } else { Pattern pattern = Pattern.compile("^(([0-9]{2}\\.[0-9]{3}-[0-9]{3})|([0-9]{2}[0-9]{3}-[0-9]{3})|([0-9]{8}))$"); Matcher matcher = pattern.matcher(cep); result = matcher.find(); } return result; } }
CepValidator implements ConstraintValidator<Cep, String> { @Override public boolean isValid(String cep, final ConstraintValidatorContext context) { boolean result = false; if ( cep == null || "".equals(cep) ) { result = true; } else { Pattern pattern = Pattern.compile("^(([0-9]{2}\\.[0-9]{3}-[0-9]{3})|([0-9]{2}[0-9]{3}-[0-9]{3})|([0-9]{8}))$"); Matcher matcher = pattern.matcher(cep); result = matcher.find(); } return result; }  }
CepValidator implements ConstraintValidator<Cep, String> { @Override public boolean isValid(String cep, final ConstraintValidatorContext context) { boolean result = false; if ( cep == null || "".equals(cep) ) { result = true; } else { Pattern pattern = Pattern.compile("^(([0-9]{2}\\.[0-9]{3}-[0-9]{3})|([0-9]{2}[0-9]{3}-[0-9]{3})|([0-9]{8}))$"); Matcher matcher = pattern.matcher(cep); result = matcher.find(); } return result; }  @Override void initialize(final Cep constraintAnnotation); @Override boolean isValid(String cep, final ConstraintValidatorContext context); }
CepValidator implements ConstraintValidator<Cep, String> { @Override public boolean isValid(String cep, final ConstraintValidatorContext context) { boolean result = false; if ( cep == null || "".equals(cep) ) { result = true; } else { Pattern pattern = Pattern.compile("^(([0-9]{2}\\.[0-9]{3}-[0-9]{3})|([0-9]{2}[0-9]{3}-[0-9]{3})|([0-9]{8}))$"); Matcher matcher = pattern.matcher(cep); result = matcher.find(); } return result; }  @Override void initialize(final Cep constraintAnnotation); @Override boolean isValid(String cep, final ConstraintValidatorContext context);  }