A JVM library written in Kotlin that adds some custom bean anotations for validating input using a bean validator like hybernate validator.
The current implementation introduces a @ValidPassword annotation to be used on bean fields and a @FieldMatch annotation for validating that 2 fields match each other.
The following parameters are available to customize password validation:
message
overrides the default error messagemessageSeparator
separator character when multiple error messages are returnedgroups
array of classes used for grouping annotation classespayload
a class that implements Payload to provide metadatamessagePropertiesLocation
the file location of a message.properties file to use for translating error messages. See the included messages.properties for an example.minLength
sets the minimum length of the password, default is 1maxLength
sets the maximum length of the password, default is Int.MAX_VALUEupperCaseCount
sets the minimum number of uppercase characters the password must containlowerCaseCount
sets the minimum number of lowercase characters the password must containalphaCharsCount
sets the minimum number of alphabetic characters the password must containnumericCharsCount
sets the minimum number of numeric characters the password must containspecialCharsCount
sets the minimum number of special characters the password must containregex
sets a regex to validate the password againstwhitespaceAllowed
sets whether whitespaces are allowed in the password, default is false
Use the parameters first
and second
to name the fields to be compared.
Use message
to specify an error message other than the default.
In order to allow for multiple instances of FieldMatch
, use the .List
property and send an array of instances of FieldMatch
as in the example below.
Example bean in Kotlin:
@FieldMatch.List([
FieldMatch(first = "password", second = "confirmPassword", message = "The password fields must match"),
FieldMatch(first = "email", second = "confirmEmail", message = "The email fields must match")
])
class NewUserForm {
@NotEmpty
var username: String? = null
@NotEmpty
@ValidPassword
var password: String? = null
@NotEmpty
@ValidPassword
var passwordConfirm: String? = null
@Email
var email: String? = null
@Email
var emailConfirm: String? = null
var roles: Array<Option> = emptyArray()
}