public class Validator extends Object
| Modifier and Type | Method and Description |
|---|---|
void |
add(String key,
String value) |
void |
email(String name)
Validates a field to be a valid email address
|
void |
email(String name,
String message)
Validates a field to be a valid email address
|
void |
exactMatch(String name,
String anotherName)
Validates to fields to exactly (case-sensitive) match
|
void |
exactMatch(String name,
String anotherName,
String message)
Validates to fields to exactly (case-sensitive) match
|
String |
get(String key) |
String |
getError(String name)
Retrieves the error message for a given field
|
Map<String,String> |
getErrors() |
boolean |
hasError(String name)
Checks if a give field has a validation error
|
boolean |
hasErrors()
Checks if any field in the validation has an error
|
void |
ipv4(String name)
Validates a field to be a valid IPv4 address
|
void |
ipv4(String name,
String message)
Validates a field to be a valid IPv4 address
|
void |
ipv6(String name)
Validates a field to be a valid IPv6 address
|
void |
ipv6(String name,
String message)
Validates a field to be a valid IPv6 address
|
void |
match(String name,
String anotherName)
Validates to fields to (case-insensitive) match
|
void |
match(String name,
String anotherName,
String message)
Validates to fields to (case-insensitive) match
|
void |
max(String name,
double maxLength)
Validates a given field to have a maximum length
|
void |
max(String name,
double maxLength,
String message)
Validates a given field to have a maximum length
|
void |
min(String name,
double minLength)
Validates a given field to have a minimum length
|
void |
min(String name,
double minLength,
String message)
Validates a given field to have a minimum length
|
void |
numeric(String name)
Validates that a given field has a numeric value
|
void |
numeric(String name,
String message)
Validates that a given field has a numeric value
|
void |
range(String name,
int minLength,
int maxLength)
Validates a field to be in a certain range
|
void |
range(String name,
int minLength,
int maxLength,
String message)
Validates a field to be in a certain range
|
void |
regex(String name,
Pattern pattern)
Validates a field by a given regular expression pattern
It is required to pass a pre-compiled pattern, e.g.
|
void |
regex(String name,
Pattern pattern,
String message)
Validates a field by a given regular expression pattern
It is required to pass a pre-compiled pattern, e.g.
|
void |
required(String name)
Validates a given field to be required
|
void |
required(String name,
String message)
Validates a given field to be required
|
void |
setValues(Map<String,String> values) |
void |
url(String name)
Validates field to be a valid URL
|
void |
url(String name,
String message)
Validates field to be a valid URL
|
@Inject public Validator(Messages messages)
public boolean hasError(String name)
name - The field to checkpublic String getError(String name)
name - The field to checkpublic void required(String name)
name - The field to checkpublic void required(String name, String message)
name - The field to checkmessage - A custom error message instead of the default onepublic void min(String name, double minLength)
name - The field to checkminLength - The minimum lengthpublic void min(String name, double minLength, String message)
name - The field to checkminLength - The minimum lengthmessage - A custom error message instead of the default onepublic void max(String name, double maxLength)
maxLength - The maximum lengthname - The field to checkpublic void numeric(String name)
name - The field to checkpublic void numeric(String name, String message)
name - The field to checkmessage - A custom error message instead of the default onepublic void max(String name, double maxLength, String message)
name - The field to checkmaxLength - The maximum lengthmessage - A custom error message instead of the default onepublic void exactMatch(String name, String anotherName)
name - The field to checkanotherName - The field to check againstpublic void exactMatch(String name, String anotherName, String message)
name - The field to checkanotherName - The field to check againstmessage - A custom error message instead of the default onepublic void match(String name, String anotherName)
name - The field to checkanotherName - The field to check againstpublic void match(String name, String anotherName, String message)
name - The field to checkanotherName - The field to check againstmessage - A custom error message instead of the default onepublic void email(String name)
name - The field to checkpublic void email(String name, String message)
name - The field to checkmessage - A custom error message instead of the default onepublic void ipv4(String name)
name - The field to checkpublic void ipv4(String name, String message)
name - The field to checkmessage - A custom error message instead of the default onepublic void ipv6(String name)
name - The field to checkpublic void ipv6(String name, String message)
name - The field to checkmessage - A custom error message instead of the default onepublic void range(String name, int minLength, int maxLength)
name - The field to checkminLength - The minimum lengthmaxLength - The maximum lengthpublic void range(String name, int minLength, int maxLength, String message)
name - The field to checkminLength - The minimum lengthmaxLength - The maximum lengthmessage - A custom error message instead of the default onepublic void regex(String name, Pattern pattern)
name - The field to checkpattern - The pre-compiled patternpublic void regex(String name, Pattern pattern, String message)
pattern - The pre-compiled patternname - The field to checkmessage - A custom error message instead of the default onepublic void url(String name)
name - The field to checkpublic void url(String name, String message)
name - The field to checkmessage - A custom error message instead of the default onepublic boolean hasErrors()
Copyright © 2016. All rights reserved.