This class helps with input validation in Java.
In this example we are validating username
//Getting the string
String username = "dirchev";
// Validating the username.
// It is required.
// Must have more than 3 characters and less than 15 characters.
// Must contain letters and numbers only.
ValidatedInput validated = new ValidatedInput(username, "Username").required().alphanum().min_length(3).max_length(15);
// Getting validation result
validated.isValid();
// > true
In this example we are validating first name
//Getting the string
String firstName = "Fakename123Fakename123Fakename123Fakename123";
// Validating the name.
// It is required.
// Must have more than 3 characters and less than 15 characters.
// Must contain only letters.
ValidatedInput validated = new ValidatedInput(firstName, "First Name").required().alpha().min_length(3).max_length(15);
// Getting validation result
validated.isValid();
// > false
// Getting validation messages
validated.getValidationMessages();
// > ['First Name' must include only letters., 'First Name' must have less than 15 characters.]
// Checks if the string has at least 1 character
.required()
// Checks if the string contains only upper or lower case letters or numbers
.alphanum()
// Checks if the string contains only upper or lower case letters
.alpha()
// Checks if the string contains only numbers
.integer()
// Checks if the string length is more than given length
.min_length(length)
// Checks if the string length is less than the given length
.max_length(length)
// Checks if the string is a valid email
.email()