@aljunggren aljunggren authored on 10 Sep 2020
src Added NotBetween validation 6 years ago
.gitignore Initial commit 6 years ago
README.md Added NotBetween validation 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 - [String] Match given value
  • matches - [String array] Match any of the given values
  • caseSensitive - [boolean] 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

Between Validation

Validates variable is between two given numbers

@BetweenValidation(minimum = 3.2, maximum = 4, inclusive = true)

Optional

  • Inclusive - [boolean] Default: false

Required

  • Minimum - [double]
  • Maximum - [double]

Data types supported

  • Number

Greater Than Validation

Validates variable is greater than given number

@GreaterThanValidation(minimum = 3.2)

Required

  • Minimum - [double]

Data types supported

  • Number

Greater Than or Equal to Validation

Validates variable is greater than or equal to given number

@GreaterThanOrEqualToValidation(minimum = 3.2)

Required

  • Minimum - [double]

Data types supported

  • Number

Less Than Validation

Validates variable is less than given number

@LessThanValidation(maximum = 3.2)

Required

  • Maximum - [double]

Data types supported

  • Number

Less Than or Equal to Validation

Validates variable is less than or equal to given number

@LessThanOrEqualToValidation(maximum = 3.2)

Required

  • Maximum - [double]

Data types supported

  • Number

Not Between Validation

Validates variable is not between two given numbers

@NotBetweenValidation(minimum = 3.2, maximum = 4, inclusive = true)

Optional

  • Inclusive - [boolean] Default: false

Required

  • Minimum - [double]
  • Maximum - [double]

Data types supported

  • Number