public class RegexConstraint
- Object
- RegexConstraint
ImplementsConstraint
Creates a validation constraint based on a regular expression
Constructors
public RegexConstraint(String regex, String errorMessage) | Creates a new regex constraint |
Methods
public static Constraint validEmail(String errorMessage) | Generates a valid email constraint by using a regular expression |
public static Constraint validEmail() | Generates a valid email constraint by using a regular expression |
public static Constraint validURL(String errorMessage) | Generates a valid URL constraint by using a regular expression |
public static Constraint validURL() | Generates a valid URL constraint by using a regular expression |
public boolean isValid(Object value) | Indicates if the given value is valid or not |
public String getDefaultFailMessage() | Includes the error message for the constraint |
Inherited methods
Constructor details
RegexConstraint
public RegexConstraint(String regex, String errorMessage)Creates a new regex constraint
Parameters
regexString- the regular expression
errorMessageString- the default error message if the constraint fails
Method details
validEmail
public static Constraint validEmail(String errorMessage)Generates a valid email constraint by using a regular expression
Parameters
errorMessageString- error message for the constraint
Returns
a constraint that will fail if the input isn’t a valid email
validEmail
public static Constraint validEmail()Generates a valid email constraint by using a regular expression
Returns
a constraint that will fail if the input isn’t a valid email
validURL
public static Constraint validURL(String errorMessage)Generates a valid URL constraint by using a regular expression
Parameters
errorMessageString- error message for the constraint
Returns
a constraint that will fail if the input isn’t a valid email
validURL
public static Constraint validURL()Generates a valid URL constraint by using a regular expression
Returns
a constraint that will fail if the input isn’t a valid email
isValid
public boolean isValid(Object value)Indicates if the given value is valid or not
Parameters
valueObject- the value for the object
Returns
true if the value is valid and false otherwise
getDefaultFailMessage
public String getDefaultFailMessage()Includes the error message for the constraint
Returns
the text of the error message for a constraint