| src | 5 years ago | ||
| .gitignore | 6 years ago | ||
| README.md | 6 years ago | ||
| pom.xml | 6 years ago | ||
Annotate member variables for validation
public class User {
@Alpha
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();
Validates variable consists of only letters
@Alpha
Data types supported
Validates variable consists of only letters and/or numbers
@AlphaNumeric
Data types supported
Validates variable against a custom class
@Custom(className = "com.ljunggren.validator.evaluation.AlphaEvaluation")
Required
Note: Custom validation class must implement the Evaluation interface
Validates variable is an email address
Data types supported
Validates variable equals given value
@ExactMatch(match = "match")
@ExactMatch(match = "match", caseSensitive = false)
@ExactMatch(matches = {"PST", "MST", "CST", "EST"})
Options
Data types supported
Note: matches array will override match string
Validates variable is of given length
@Length(length = 4)
Required
Data types supported
Validates variable is not empty
@NotEmpty
Data types supported
Validates variable is not null
@NotNull
Data types supported
Will override all other validations if variable is null
@Optional
Data types supported
Validates variable matches given regex
@Regex(regex = "^[a-zA-Z]+$")
Required
Data types supported
Validates variable is of given size
@Size(size = 3)
Required
Data types supported
Validates variable is between two given numbers
@Between(minimum = 3.2, maximum = 4, inclusive = true)
Optional
Required
Data types supported
Validates variable is greater than given number
@GreaterThan(minimum = 3.2)
Required
Data types supported
Validates variable is greater than or equal to given number
@GreaterThanOrEqualTo(minimum = 3.2)
Required
Data types supported
Validates variable is less than given number
@LessThan(maximum = 3.2)
Required
Data types supported
Validates variable is less than or equal to given number
@LessThanOrEqualTo(maximum = 3.2)
Required
Data types supported
Validates variable is not between two given numbers
@NotBetween(minimum = 3.2, maximum = 4, inclusive = true)
Optional
Required
Data types supported
Validates variable contains a given value
@Contains(text = "contain") @Contains(startText = "contain", caseSensitive = false)
Options
Data types supported
Validates variable starts with given value
@StartsWith(startText = "Begins") @StartsWith(startText = "Begins", caseSensitive = false)
Options
Data types supported
Validates variable begins with given value
@EndsWith(endText = "Begins") @EndsWith(endText = "Begins", caseSensitive = false)
Options
Data types supported