Enum StringValidators
- All Implemented Interfaces:
Serializable, Comparable<StringValidators>, java.lang.constant.Constable, Validator<String>
Also contains static factory methods for validators which do things like match regexp's and split strings and run another validator over the components.
- Author:
- Tim Boudreau
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionFactory for validators that require the passed string to be a valid character set name according to the specification ofjava.nio.Charset.forName(String).Factory for validators that validate standard internet email addresses (name + @ + valid hostname or ip).Factory for validators that require that a string represent a file which is a directory, not a data fileFactory for validators that require that a string represent a file which is a file, not a directoryFactory for validators that require that a string represent a file which exists on diskValidator which only passes non-existent file namesFactory for validators that check the validity of an host name (may contain port info)Factory for validators that check the validity of an IP address or host name (may contain port info)Factory for validators that check the validity of an IP address (may contain port info)Factory for validators that validate a java package name.Validator which fails any string that ends with a .Factory for validators that do not allow strings which start with a digitFactory for validators that require that strings not contain whitespaceFactory for validators which require that strings not be a Java keywordFactory for validators which require non-zero length text.Factory for validators which require a non-negative number (may be floating point or int)Factory for validators which require a legal filenameFactory for validators which require a valid integerFactory for validators which require a valid number of some sortFactory for validators that require that a string represent a valid URLFactory for validators that require that strings be a valid hexadecimal number -
Method Summary
Modifier and TypeMethodDescriptionbetween(int min, int max) disallowChars(char[] chars) Get a validator which fails if any of the characters in the passed char array are contained in the evaluated textencodableInCharset(String charsetName) Get a validator which determines if the passed string can be encoded in the specified encoding.Get a validator that uses a specificFormat(e.g.greaterThan(int amount) Validate that a string evaluates to a number greater than an amountlessThan(int amount) Validate that a string evaluates to a number less than an amountmaxLength(int length) Validator that enforces maximum input lengthmayNotEndWith(char ch) Create a validator which does not allow you to terminate a string with a particular characterminLength(int length) Validator that enforces minimum input lengthThe type of the model object which can be validated.numberRange(Number min, Number max) Get a validator that guarantees that a number is within a certain range (inclusive)Get a validator which fails if the text to validate does not match a passed regular expression.splitString(String regexp, Validator<String> validator) Returns a validator which first splits the string to be evaluated according to the passed regexp, then passes each component of the split string to the passed validator.splitString(String regexp, Validator<String>... validators) Returns a validator which first splits the string to be evaluated according to the passed regexp, then passes each component of the split string to the passed validator.trim()Returns a Validatorthat will first call trim()on theStringto be validated, and then passes the resulting (trimmed)Stringto this instance ofStringValidators.trimString(Validator<String> validator) Creates aValidator<String>that will first calltrim()on theStringto be validated, and then passes the resulting (trimmed)Stringto the passedValidator<String>.trimString(Validator<String>... validators) Creates aValidator<String>that will first calltrim()on theStringto be validated, and then passes the resulting (trimmed)Stringto the passedValidator<String>(or chain thereof).voidValidate the passed model.Create a number validator that uses a specific locale.static StringValidatorsReturns the enum constant of this type with the specified name.static StringValidators[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
REQUIRE_NON_EMPTY_STRING
Factory for validators which require non-zero length text. -
REQUIRE_VALID_FILENAME
Factory for validators which require a legal filename -
REQUIRE_VALID_INTEGER
Factory for validators which require a valid integer -
REQUIRE_NON_NEGATIVE_NUMBER
Factory for validators which require a non-negative number (may be floating point or int) -
REQUIRE_VALID_NUMBER
Factory for validators which require a valid number of some sort -
REQUIRE_JAVA_IDENTIFIER
Factory for validators which require that strings not be a Java keyword -
VALID_HEXADECIMAL_NUMBER
Factory for validators that require that strings be a valid hexadecimal number -
NO_WHITESPACE
Factory for validators that require that strings not contain whitespace -
FILE_MUST_EXIST
Factory for validators that require that a string represent a file which exists on disk -
FILE_MUST_BE_FILE
Factory for validators that require that a string represent a file which is a file, not a directory -
FILE_MUST_BE_DIRECTORY
Factory for validators that require that a string represent a file which is a directory, not a data file -
URL_MUST_BE_VALID
Factory for validators that require that a string represent a valid URL -
IP_ADDRESS
Factory for validators that check the validity of an IP address (may contain port info) -
HOST_NAME
Factory for validators that check the validity of an host name (may contain port info) -
HOST_NAME_OR_IP_ADDRESS
Factory for validators that check the validity of an IP address or host name (may contain port info) -
MAY_NOT_START_WITH_DIGIT
Factory for validators that do not allow strings which start with a digit -
EMAIL_ADDRESS
Factory for validators that validate standard internet email addresses (name + @ + valid hostname or ip).Note: This validator is not useful for all legal email addresses - for example, "root" with is a legal email address on a Unix machine. Do not use this validator where users might legitimately expect to be able to enter such unqualified email addresses.
-
CHARACTER_SET_NAME
Factory for validators that require the passed string to be a valid character set name according to the specification ofjava.nio.Charset.forName(String). -
JAVA_PACKAGE_NAME
Factory for validators that validate a java package name. Note that this does not mean the package name actually exists anywhere, just that it does not contain java keywords. -
FILE_MUST_NOT_EXIST
Validator which only passes non-existent file names -
MAY_NOT_END_WITH_PERIOD
Validator which fails any string that ends with a .
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
validate
Description copied from interface:ValidatorValidate the passed model. If the component is invalid, this method shall add problems to the passed list. -
trim
Returns a Validatorthat will first call trim()on theStringto be validated, and then passes the resulting (trimmed)Stringto this instance ofStringValidators.See also the static
trimString(org.netbeans.validation.api.Validator[])that does a similar thing for anyValidator<String>(or a chain thereof) that need not be an instance of theStringValidatorsenum -
trimString
Creates aValidator<String>that will first calltrim()on theStringto be validated, and then passes the resulting (trimmed)Stringto the passedValidator<String>(or chain thereof).See also
ValidatorUtils.merge(org.netbeans.validation.api.Validator[])which merges validators (anyValidator, not justValidator<String>) without wrapping the result in one that does String trimming.- Parameters:
validators- a chain of String validators
-
trimString
Creates aValidator<String>that will first calltrim()on theStringto be validated, and then passes the resulting (trimmed)Stringto the passedValidator<String>.Unlike
trimString(Validator...), calling this method does not trigger warnings under-Xlint:unchecked. If you wish to trim more than one validator, simply trim the result ofValidatorUtils.merge(Validator,Validator).- Parameters:
validator- a String validator
-
splitString
@SafeVarargs public static Validator<String> splitString(String regexp, Validator<String>... validators) Returns a validator which first splits the string to be evaluated according to the passed regexp, then passes each component of the split string to the passed validator.- Parameters:
regexp- The regular expression pattern to use to split the stringvalidators- the validator (or chain of validators) that the returned one should delegate to validate each component of the split string- Returns:
- A validator which evaluates each of component of the split string using the passed Validator (or chain of validators)
-
splitString
Returns a validator which first splits the string to be evaluated according to the passed regexp, then passes each component of the split string to the passed validator.Unlike
splitString(String,Validator...), calling this method does not trigger warnings under-Xlint:unchecked. If you wish to split more than one validator, simply split the result ofValidatorUtils.merge(Validator,Validator).- Parameters:
regexp- The regular expression pattern to use to split the stringvalidator- the validator that the returned one should delegate to validate each component of the split string- Returns:
- A validator which evaluates each of component of the split string using the passed Validator
-
mayNotEndWith
-
disallowChars
Get a validator which fails if any of the characters in the passed char array are contained in the evaluated text- Parameters:
chars- The array of illegal characters- Returns:
- A validator which will show an error if any of the passed characters are in the String it encounters
-
regexp
Get a validator which fails if the text to validate does not match a passed regular expression.- Parameters:
regexp- The regular expressionmessage- The output message if there is a problem. The message may refer to the component name as {0} and the text that has not matched as {1} if desiredacceptPartialMatches- if true, will useMatcher.lookingAt()rather thanMatcher.matches()- Returns:
- A validator
-
validNumber
Create a number validator that uses a specific locale. For the default locale, use StringValidators.REQUIRE_VALID_NUMBER. Use this if you specifically want validation for another locale.- Parameters:
l- The locale to use- Returns:
- A string validator for numbers
-
forFormat
-
encodableInCharset
Get a validator which determines if the passed string can be encoded in the specified encoding. Useful, for example, for validating strings that are specified to be in a particular encoding (e.g. email addresses and US-ASCII)- Parameters:
charsetName- The name of a character set recognized byjava.nio.Charset- Returns:
- A validator of character set names
- Throws:
UnsupportedCharsetException- if the character set is unsupportedIllegalCharsetNameException- if the character set is illegal
-
numberRange
-
minLength
-
maxLength
-
greaterThan
-
lessThan
-
between
-
modelType
Description copied from interface:ValidatorThe type of the model object which can be validated. Necessary due to limitations of the Java implementation of generics, so that model conversions can be done at runtime, and declaratively registered ValidationListeners can be matched with Validator types. The return value of this method is expected to remain constant throughout the life of this validator.
-