public enum StringValidators extends java.lang.Enum<StringValidators> implements Validator<java.lang.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.
Enum Constant and Description |
---|
CHARACTER_SET_NAME
Factory for validators that require the passed string to be a valid
character set name according to the specification of
java.nio.Charset.forName(String) . |
EMAIL_ADDRESS
Factory for validators that validate standard internet email addresses
(name + @ + valid hostname or ip).
|
FILE_MUST_BE_DIRECTORY
Factory for validators that require that a string represent a file
which is a directory, not a data file
|
FILE_MUST_BE_FILE
Factory for validators that require that a string represent a file
which is a file, not a directory
|
FILE_MUST_EXIST
Factory for validators that require that a string represent a file
which exists on disk
|
FILE_MUST_NOT_EXIST
Validator which only passes non-existent file names
|
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)
|
IP_ADDRESS
Factory for validators that check the validity of an IP address (may
contain port info)
|
JAVA_PACKAGE_NAME
Factory for validators that validate a java package name.
|
MAY_NOT_END_WITH_PERIOD
Validator which fails any string that ends with a .
|
MAY_NOT_START_WITH_DIGIT
Factory for validators that do not allow strings which start with
a digit
|
NO_WHITESPACE
Factory for validators that require that strings not contain whitespace
|
REQUIRE_JAVA_IDENTIFIER
Factory for validators which require that strings not be a
Java keyword
|
REQUIRE_NON_EMPTY_STRING
Factory for validators which require non-zero length text.
|
REQUIRE_NON_NEGATIVE_NUMBER
Factory for validators which require a non-negative number (may
be floating point or int)
|
REQUIRE_VALID_FILENAME
Factory for validators which require a legal filename
|
REQUIRE_VALID_INTEGER
Factory for validators which require a valid integer
|
REQUIRE_VALID_NUMBER
Factory for validators which require a valid number of some sort
|
URL_MUST_BE_VALID
Factory for validators that require that a string represent a valid URL
|
VALID_HEXADECIMAL_NUMBER
Factory for validators that require that strings be a valid
hexadecimal number
|
Modifier and Type | Method and Description |
---|---|
static Validator<java.lang.String> |
disallowChars(char[] chars)
Get a validator which fails if any of the characters in the
passed char array are contained in the evaluated text
|
static Validator<java.lang.String> |
encodableInCharset(java.lang.String charsetName)
Get a validator which determines if the passed string can be encoded
in the specified encoding.
|
static Validator<java.lang.String> |
forFormat(java.text.Format fmt)
Get a validator that uses a specific
Format (e.g. |
static Validator<java.lang.String> |
maxLength(int length)
Validator that enforces maximum input length
|
static Validator<java.lang.String> |
mayNotEndWith(char ch)
Create a validator which does not allow you to terminate a string
with a particular character
|
static Validator<java.lang.String> |
minLength(int length)
Validator that enforces minimum input length
|
java.lang.Class<java.lang.String> |
modelType()
The type of the model object which can be validated.
|
static Validator<java.lang.String> |
numberRange(java.lang.Number min,
java.lang.Number max)
Get a validator that guarantees that a number is within a certain
range (inclusive)
|
static Validator<java.lang.String> |
regexp(java.lang.String regexp,
java.lang.String message,
boolean acceptPartialMatches)
Get a validator which fails if the text to validate does not match a
passed regular expression.
|
static Validator<java.lang.String> |
splitString(java.lang.String regexp,
Validator<java.lang.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.
|
static Validator<java.lang.String> |
splitString(java.lang.String regexp,
Validator<java.lang.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.
|
Validator<java.lang.String> |
trim()
Returns a Validator
trim() on the String to be validated,
and then passes the resulting (trimmed) String to this instance of StringValidators . |
static Validator<java.lang.String> |
trimString(Validator<java.lang.String>... validators)
Creates a
Validator<String> that will first call trim() on the String to be validated,
and then passes the resulting (trimmed) String to the passed Validator<String> (or chain thereof). |
static Validator<java.lang.String> |
trimString(Validator<java.lang.String> validator)
Creates a
Validator<String> that will first call trim() on the String to be validated,
and then passes the resulting (trimmed) String to the passed Validator<String> . |
void |
validate(Problems problems,
java.lang.String compName,
java.lang.String model)
Validate the passed model.
|
static Validator<java.lang.String> |
validNumber(java.util.Locale l)
Create a number validator that uses a specific locale.
|
static StringValidators |
valueOf(java.lang.String name)
Returns 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.
|
public static final StringValidators REQUIRE_NON_EMPTY_STRING
public static final StringValidators REQUIRE_VALID_FILENAME
public static final StringValidators REQUIRE_VALID_INTEGER
public static final StringValidators REQUIRE_NON_NEGATIVE_NUMBER
public static final StringValidators REQUIRE_VALID_NUMBER
public static final StringValidators REQUIRE_JAVA_IDENTIFIER
public static final StringValidators VALID_HEXADECIMAL_NUMBER
public static final StringValidators NO_WHITESPACE
public static final StringValidators FILE_MUST_EXIST
public static final StringValidators FILE_MUST_BE_FILE
public static final StringValidators FILE_MUST_BE_DIRECTORY
public static final StringValidators URL_MUST_BE_VALID
public static final StringValidators IP_ADDRESS
public static final StringValidators HOST_NAME
public static final StringValidators HOST_NAME_OR_IP_ADDRESS
public static final StringValidators MAY_NOT_START_WITH_DIGIT
public static final StringValidators EMAIL_ADDRESS
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.
public static final StringValidators CHARACTER_SET_NAME
java.nio.Charset.forName(String)
.public static final StringValidators JAVA_PACKAGE_NAME
public static final StringValidators FILE_MUST_NOT_EXIST
public static final StringValidators MAY_NOT_END_WITH_PERIOD
public static StringValidators[] values()
for (StringValidators c : StringValidators.values()) System.out.println(c);
public static StringValidators valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant
with the specified namejava.lang.NullPointerException
- if the argument is nullpublic void validate(Problems problems, java.lang.String compName, java.lang.String model)
Validator
public Validator<java.lang.String> trim()
trim()
on the String
to be validated,
and then passes the resulting (trimmed) String
to this instance of StringValidators
.
See also the static trimString(org.netbeans.validation.api.Validator[])
that does a similar thing for any Validator<String>
(or a chain thereof)
that need not be an instance of the StringValidators
enum
public static Validator<java.lang.String> trimString(Validator<java.lang.String>... validators)
Validator<String>
that will first call trim()
on the String
to be validated,
and then passes the resulting (trimmed) String
to the passed Validator<String>
(or chain thereof).
See also ValidatorUtils.merge(org.netbeans.validation.api.Validator[])
which merges validators (any Validator
, not just Validator<String>
) without wrapping the result in one
that does String trimming.
validators
- a chain of String validatorspublic static Validator<java.lang.String> trimString(Validator<java.lang.String> validator)
Validator<String>
that will first call trim()
on the String
to be validated,
and then passes the resulting (trimmed) String
to the passed Validator<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 of ValidatorUtils.merge(Validator,Validator)
.
validator
- a String validatorpublic static Validator<java.lang.String> splitString(java.lang.String regexp, Validator<java.lang.String>... validators)
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 stringpublic static Validator<java.lang.String> splitString(java.lang.String regexp, Validator<java.lang.String> 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 of ValidatorUtils.merge(Validator,Validator)
.
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 stringpublic static Validator<java.lang.String> mayNotEndWith(char ch)
ch
- The characterpublic static Validator<java.lang.String> disallowChars(char[] chars)
chars
- The array of illegal characterspublic static Validator<java.lang.String> regexp(java.lang.String regexp, java.lang.String message, boolean acceptPartialMatches)
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 use Matcher.lookingAt()
rather
than Matcher.matches()
public static Validator<java.lang.String> validNumber(java.util.Locale l)
l
- The locale to usepublic static Validator<java.lang.String> forFormat(java.text.Format fmt)
Format
(e.g.
NumberFormat
) instance and fails
if fmt.parseObject()
throws a ParseException
fmt
- A java.text.Format
NumberFormat
public static Validator<java.lang.String> encodableInCharset(java.lang.String charsetName)
charsetName
- The name of a character set recognized by
java.nio.Charset
java.nio.charset.UnsupportedCharsetException
- if the character set is unsupportedjava.nio.charset.IllegalCharsetNameException
- if the character set is illegalpublic static Validator<java.lang.String> numberRange(java.lang.Number min, java.lang.Number max)
min
- The minimum valuemax
- The maximum valuepublic static Validator<java.lang.String> minLength(int length)
length
- public static Validator<java.lang.String> maxLength(int length)
length
- public java.lang.Class<java.lang.String> modelType()
Validator