@aljunggren aljunggren authored on 5 Sep 2020
src Added SizeValidation 6 years ago
.gitignore Initial commit 6 years ago
README.md Added SizeValidation 6 years ago
pom.xml Formatting, changed tabs to spaces 6 years ago
README.md

Validator

Annotate member variables for validation

public class User {
    @AlphaValidation
    private String firstName;
}

Instantiate

Validator validator = new Validator(object);

Validate

validator.validate();

Check validity of object

validator.isValid();

Get invalid Items

List<Item> items = validator.getInvalidItems();

Get member name for invalid Item

items.get(0).getMemberName();

Get error message for invalid Item

items.get(0).getErrorMessage();

Alpha Validation

Validates variable consists of only letters

@AlphaValidation

Data types supported

  • String

AlphaNumeric Validation

Validates variable consists of only letters and/or numbers

@AlphaNumericValidation

Data types supported

  • String

Custom Validation

Validates variable against a custom class

@CustomValidation(className = "com.ljunggren.validator.evaluation.AlphaEvaluation")

Required

  • className - [String] Package and class name of custom validation class

Note: Custom validation class must implement the Evaluation interface

Email Validation

Validates variable is an email address

@EmailValidation

Data types supported

  • String

Exact Match Validation

Validates variable equals given value

@ExactMatchValidation(match = "match")
@ExactMatchValidation(match = "match", caseSensitive = false)
@ExactMatchValidation(matches = {"PST", "MST", "CST", "EST"})

Options

  • match - Match given value
  • matches - Match any of the given values
  • caseSensitive - Default: true

Data types supported

  • String
  • Number

Note: matches array will override match string

Length Validation

Validates variable is of given length

@LengthValidation(length = 4)

Required

  • length - [int]

Data types supported

  • String
  • Integer
  • Long

Not Empty Validation

Validates variable is not empty

@NotEmptyValidation

Data types supported

  • String
  • Array
  • Collection
  • Map

Not Null Validation

Validates variable is not null

@NotNullValidation

Data types supported

  • Any Object

Optional Validation

Will override all other validations if variable is null

@OptionalValidation

Data types supported

  • Any Object

Regex Validation

Validates variable matches given regex

@RegexValidation(regex = "^[a-zA-Z]+$")

Required

  • regex - [String]

Data types supported

  • String

Size Validation

Validates variable is of given size

@SizeValidation(size = 3)

Required

  • Size - [int]

Data types supported

  • Array
  • Collection
  • Map