Package io.mangoo.routing.bindings
Class Validator
java.lang.Object
io.mangoo.routing.bindings.Validator
- All Implemented Interfaces:
Serializable
- Author:
- svenkubiak
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidexpectDomainName(String name) Validates a field to be a valid Domain namevoidexpectDomainName(String name, String message) Validates a field to be a valid Domain namevoidexpectEmail(String name) Validates a field to be a valid email addressvoidexpectEmail(String name, String message) Validates a field to be a valid email addressvoidexpectExactMatch(String name, String anotherName) Validates two fields to exactly (case-sensitive) matchvoidexpectExactMatch(String name, String anotherName, String message) Validates two fields to exactly (case-sensitive) matchvoidexpectFalse(String name, boolean value) Validates a given value to be falsevoidexpectFalse(String name, boolean value, String message) Validates a given value to be falsevoidexpectIpv4(String name) Validates a field to be a valid IPv4 addressvoidexpectIpv4(String name, String message) Validates a field to be a valid IPv4 addressvoidexpectIpv6(String name) Validates a field to be a valid IPv6 addressvoidexpectIpv6(String name, String message) Validates a field to be a valid IPv6 addressvoidexpectMatch(String name, String anotherName) Validates two fields to (case-insensitive) matchvoidexpectMatch(String name, String anotherName, String message) Validates two fields to (case-insensitive) matchvoidexpectMatch(String name, String message, List<String> values) Validates a list of value to (case-sensitive) matchvoidexpectMatch(String name, List<String> values) Validates a list of given values to (case-sensitive) matchvoidexpectMaxLength(String name, double maxLength) Validates a given field to have a maximum lengthvoidexpectMaxLength(String name, double maxLength, String message) Validates a given field to have a maximum lengthvoidexpectMaxValue(String name, double maxValue) Validates a given field to have a maximum valuevoidexpectMaxValue(String name, double maxValue, String message) Validates a given field to have a maximum valuevoidexpectMinLength(String name, double minLength) Validates a given field to have a minimum lengthvoidexpectMinLength(String name, double minLength, String message) Validates a given field to have a minimum lengthvoidexpectMinValue(String name, double minValue) Validates a given field to have a minimum valuevoidexpectMinValue(String name, double minValue, String message) Validates a given field to have a minimum valuevoidexpectNotNull(String name, Object object) Validates a given object to be not nullvoidexpectNotNull(String name, Object object, String message) Validates a given object to be not nullvoidexpectNull(String name, Object object) Validates a given object to be nullvoidexpectNull(String name, Object object, String message) Validates a given object to be nullvoidexpectNumeric(String name) Validates that a given field has a numeric valuevoidexpectNumeric(String name, String message) Validates that a given field has a numeric valuevoidexpectRangeLength(String name, int minLength, int maxLength) Validates a field to be in a certain range lengthvoidexpectRangeLength(String name, int minLength, int maxLength, String message) Validates a field to be in a certain range lengthvoidexpectRangeValue(String name, int minValue, int maxValue) Validates a field to be in a certain range valuevoidexpectRangeValue(String name, int minValue, int maxValue, String message) Validates a field to be in a certain range valuevoidexpectRegex(String name, com.google.re2j.Pattern pattern) Validates a field by a given regular expression pattern It is required to pass a pre-compiled pattern, e.g.voidexpectRegex(String name, com.google.re2j.Pattern pattern, String message) Validates a field by a given regular expression pattern It is required to pass a pre-compiled pattern, e.g.voidexpectTrue(String name, boolean value) Validates a given value to be truevoidexpectTrue(String name, boolean value, String message) Validates a given value to be truevoidValidates field to be a valid URLvoidValidates field to be a valid URLvoidexpectValue(String name) Validates a given field to be present with a valuevoidexpectValue(String name, String message) Validates a given field to be present with a valueRetrieves a form value corresponding to the name of the form elementRetrieves the error message for a given fieldbooleanChecks if a give field has a validation errorbooleanChecks if any field in the validation has an errorvoidbooleanisValid()void
-
Constructor Details
-
Validator
public Validator()
-
-
Method Details
-
hasError
Checks if a give field has a validation error- Parameters:
name- The field to check- Returns:
- True if the field has a validation error, false otherwise
-
getError
Retrieves the error message for a given field- Parameters:
name- The field to check- Returns:
- The error message for the field, or an empty string if no error is found
-
expectValue
Validates a given field to be present with a value- Parameters:
name- The field to check
-
expectValue
Validates a given field to be present with a value- Parameters:
name- The field to checkmessage- A custom error message instead of the default one
-
expectMinValue
Validates a given field to have a minimum value- Parameters:
name- The field to checkminValue- The minimum value
-
expectMinValue
Validates a given field to have a minimum value- Parameters:
name- The field to checkminValue- The minimum valuemessage- A custom error message instead of the default one
-
expectMinLength
Validates a given field to have a minimum length- Parameters:
name- The field to checkminLength- The minimum length
-
expectMinLength
Validates a given field to have a minimum length- Parameters:
name- The field to checkminLength- The minimum lengthmessage- A custom error message instead of the default one
-
expectMaxValue
Validates a given field to have a maximum value- Parameters:
maxValue- The maximum valuename- The field to check
-
expectMaxLength
Validates a given field to have a maximum length- Parameters:
maxLength- The maximum lengthname- The field to check
-
expectNumeric
Validates that a given field has a numeric value- Parameters:
name- The field to check
-
expectNumeric
Validates that a given field has a numeric value- Parameters:
name- The field to checkmessage- A custom error message instead of the default one
-
expectMaxLength
Validates a given field to have a maximum length- Parameters:
name- The field to checkmaxLength- The maximum lengthmessage- A custom error message instead of the default one
-
expectMaxValue
Validates a given field to have a maximum value- Parameters:
name- The field to checkmaxValue- The maximum valuemessage- A custom error message instead of the default one
-
expectExactMatch
Validates two fields to exactly (case-sensitive) match- Parameters:
name- The field to checkanotherName- The other field to check against
-
expectExactMatch
Validates two fields to exactly (case-sensitive) match- Parameters:
name- The field to checkanotherName- The other field to check againstmessage- A custom error message instead of the default one
-
expectMatch
Validates two fields to (case-insensitive) match- Parameters:
name- The field to checkanotherName- The field to check against
-
expectMatch
Validates two fields to (case-insensitive) match- Parameters:
name- The field to checkanotherName- The field to check againstmessage- A custom error message instead of the default one
-
expectMatch
Validates a list of given values to (case-sensitive) match- Parameters:
name- The field to checkvalues- A list of given values to check against
-
expectMatch
Validates a list of value to (case-sensitive) match- Parameters:
name- The field to checkmessage- A custom error message instead of the default onevalues- A list of given values to check against
-
expectEmail
Validates a field to be a valid email address- Parameters:
name- The field to check
-
expectEmail
Validates a field to be a valid email address- Parameters:
name- The field to checkmessage- A custom error message instead of the default one
-
expectIpv4
Validates a field to be a valid IPv4 address- Parameters:
name- The field to check
-
expectIpv4
Validates a field to be a valid IPv4 address- Parameters:
name- The field to checkmessage- A custom error message instead of the default one
-
expectDomainName
Validates a field to be a valid Domain name- Parameters:
name- The field to check
-
expectDomainName
Validates a field to be a valid Domain name- Parameters:
name- The field to checkmessage- A custom error message instead of the default one
-
expectIpv6
Validates a field to be a valid IPv6 address- Parameters:
name- The field to check
-
expectIpv6
Validates a field to be a valid IPv6 address- Parameters:
name- The field to checkmessage- A custom error message instead of the default one
-
expectRangeLength
Validates a field to be in a certain range length- Parameters:
name- The field to checkminLength- The minimum lengthmaxLength- The maximum length
-
expectRangeValue
Validates a field to be in a certain range value- Parameters:
name- The field to checkminValue- The minimum valuemaxValue- The maximum value
-
expectRangeValue
Validates a field to be in a certain range value- Parameters:
name- The field to checkminValue- The minimum valuemaxValue- The maximum valuemessage- A custom error message instead of the default one
-
expectRangeLength
Validates a field to be in a certain range length- Parameters:
name- The field to checkminLength- The minimum lengthmaxLength- The maximum lengthmessage- A custom error message instead of the default one
-
expectRegex
Validates a field by a given regular expression pattern It is required to pass a pre-compiled pattern, e.g. Pattern pattern = Pattern.compile("[a-Z,0-9]")- Parameters:
name- The field to checkpattern- The pre-compiled pattern
-
expectRegex
Validates a field by a given regular expression pattern It is required to pass a pre-compiled pattern, e.g. Pattern pattern = Pattern.compile("[a-Z,0-9]")- Parameters:
pattern- The pre-compiled patternname- The field to checkmessage- A custom error message instead of the default one
-
expectUrl
Validates field to be a valid URL- Parameters:
name- The field to check
-
expectUrl
Validates field to be a valid URL- Parameters:
name- The field to checkmessage- A custom error message instead of the default one
-
expectTrue
Validates a given value to be true- Parameters:
name- The name of the field to display the error messagevalue- The value to checkmessage- A custom error message instead of the default one
-
expectTrue
Validates a given value to be true- Parameters:
name- The name of the field to display the error messagevalue- The value to check
-
expectFalse
Validates a given value to be false- Parameters:
name- The name of the field to display the error messagevalue- The value to checkmessage- A custom error message instead of the default one
-
expectFalse
Validates a given value to be false- Parameters:
name- The name of the field to display the error messagevalue- The value to check
-
expectNotNull
Validates a given object to be not null- Parameters:
name- The name of the field to display the error messageobject- The object to checkmessage- A custom error message instead of the default one
-
expectNotNull
Validates a given object to be not null- Parameters:
name- The name of the field to display the error messageobject- The object to check
-
expectNull
Validates a given object to be null- Parameters:
name- The name of the field to display the error messageobject- The object to checkmessage- A custom error message instead of the default one
-
expectNull
Validates a given object to be null- Parameters:
name- The name of the field to display the error messageobject- The object to check
-
hasErrors
public boolean hasErrors()Checks if any field in the validation has an error- Returns:
- True if at least one field has an error, false otherwise
-
get
Retrieves a form value corresponding to the name of the form element- Parameters:
key- The name of the form element- Returns:
- The value of the form or null if not present
-
getErrors
-
setValues
-
addValue
-
isValid
public boolean isValid() -
invalidate
public void invalidate()
-