Skip to content
Michael Edgar edited this page Apr 26, 2018 · 4 revisions

Welcome to the validators wiki!

Validators is a Java library for Bean validation covering common validation scenarios without the baggage of additional third-party dependencies.

Components

1) DateTime Constraint

Use the @DateTime constraint to validate that a sequence of characters matches at least one of the date patterns provided.

class TestBean {
    @DateTime(patterns = "yyyy-MM-dd", message = "Invalid ISO date")
    String isoDate;

    public Date getIsoDate() {
        try {
            return new SimpleDateFormat("yyyy-MM-dd").parse(isoDate);
        } catch (ParseException e) {
            // Exception will not occur if the bean instance has been validated successfully.
        }
        return null;
    }
}

2) Expression Constraint

The @Expression constraint should be used in scenarios where either multiple fields must be considered or where slightly more complicated logic is necessary to check for an individual field's validity.

Clone this wiki locally