Class ValidationUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Pattern
Regular expression Pattern to match a Social Security Number (SSN).static final Pattern
Regular expression Pattern to match a North American Numbering Plan (NANP) telephone number.static final Pattern
Regular expression Pattern to match a URL with a `http`, `https`, `ftp`, or `file` scheme.static final Pattern
Regular expression to match a Version 4 Universally Unique Identifier (UUID), in a case-insensitive fashion.static final Pattern
Regular expression to match a Version 4 Universally Unique Identifier (UUID), in a case-insensitive fashion.static final String
Regular expression to match a valid variable name.static final Pattern
Regular expression Pattern to match a United States Postal Service (USPS) ZIP Code. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Verifies if the incoming object is binary or notstatic boolean
isBoxClass
(Object value) Verifies the incoming object is a Box Classstatic boolean
Verifies the incoming object is a Closurestatic boolean
Verifies if the incoming object is a float or notstatic boolean
isFunction
(Object value) Verifies the incoming object is a Functionstatic boolean
Verifies the incoming object is a Lambdastatic boolean
Verifies the incoming object is a Functionstatic boolean
isValidCreditCard
(String cardNumber) Perform the Lunh algorithm to validate a credit card number.static boolean
isValidEmail
(String email) Verifies if the incoming object is a valid email addressstatic boolean
isValidGUID
(String uuid) Validates the given string is a valid Version 4 UUID - in SQL Server, this is known as a GUID.static boolean
isValidInteger
(Object value) Validates the given string is a valid integer value.static boolean
isValidMatch
(String value, String regex) Verifies if the incoming value matches the passed regular expressionstatic boolean
isValidMatchNoCase
(String value, String regex) Verifies if the incoming value matches the passed regular expression without case-sensitivitystatic boolean
isValidNumeric
(Object value) Validates the given string is a valid numeric value.static boolean
isValidPattern
(String value, String pattern) Verifies that the incoming string matches the incoming regex patternstatic boolean
isValidRange
(Object value, Double min, Double max) Verifies if the incoming object is within the incoming min and max rangestatic boolean
isValidSSN
(String ssn) Validates a Social Security Number (SSN) in the format of 123-45-6789 or 123456789.static boolean
isValidTelephone
(String phone) Validates a North American Numbering Plan (NANP) telephone number.static boolean
isValidURL
(String url) Validates a URL string.static boolean
isValidUUID
(String uuid) Validates the given string is a valid compatible UUID.static boolean
isValidVariableName
(String variableName) Validates a variable name is valid.static boolean
isValidZipCode
(String zipCode) Validates US-only postal codes.
-
Field Details
-
URL
Regular expression Pattern to match a URL with a `http`, `https`, `ftp`, or `file` scheme. -
TELEPHONE
Regular expression Pattern to match a North American Numbering Plan (NANP) telephone number. This does not support international numbers. -
ZIPCODE
Regular expression Pattern to match a United States Postal Service (USPS) ZIP Code. -
SSN
Regular expression Pattern to match a Social Security Number (SSN). -
UUID_V4
Regular expression to match a Version 4 Universally Unique Identifier (UUID), in a case-insensitive fashion. -
UUID_PATTERN
Regular expression to match a Version 4 Universally Unique Identifier (UUID), in a case-insensitive fashion. -
VALID_VARIABLE_REGEX
Regular expression to match a valid variable name.- See Also:
-
-
Constructor Details
-
ValidationUtil
public ValidationUtil()
-
-
Method Details
-
isValidCreditCard
Perform the Lunh algorithm to validate a credit card number.Validates that the card is between 12 and 19 digits long, contains no alphabetic characters, and passes the Luhn algorithm.
Does not validate:
- the existence of the card number
- the card number prefix
- whether the card number length matches the prefix. (For example, Visa card numbers can be 13, 16, or 19 characters depending on the sub brand.)
More extensive validation is required to ensure a card number is valid, and should be performed by either the card issuer or a third-party validation library such as Apache Commons Validator.
- Parameters:
cardNumber
- String to check for a valid credit card number format.- Returns:
- Boolean indicating whether the given string is a valid credit card number.
-
isValidInteger
Validates the given string is a valid integer value.- Parameters:
value
- String or object value to check for a valid integer format. Only Integer types or strings containing ONLY digits will return true.- Returns:
- Boolean indicating whether the given string is a valid integer
-
isValidNumeric
Validates the given string is a valid numeric value.- Parameters:
value
- String or object value to check for a valid numeric format, including Number types and strings containing numeric values.- Returns:
- Boolean indicating whether the given string is a valid numeric value.
-
isValidGUID
Validates the given string is a valid Version 4 UUID - in SQL Server, this is known as a GUID.Beware: This will not match values from
createUUID()
. For that, useisValidUUID(String)
.- Parameters:
uuid
- String to check for a valid compatible UUID format.- Returns:
- Boolean indicating whether the given string is a valid compatible UUID.
-
isValidUUID
Validates the given string is a valid compatible UUID.A compat UUID is a version 4 UUID with the final hypen removed. If you want to validate a standard UUID, use
isValidGUID(String)
.- Parameters:
uuid
- String to check for a valid compatible UUID format.- Returns:
- Boolean indicating whether the given string is a valid compatible UUID.
-
isValidSSN
Validates a Social Security Number (SSN) in the format of 123-45-6789 or 123456789.Expressly disallows certain invalid SSNs, such as 000-00-0000, 666-xx-xxxx, and 9xx-xx-xxxx, as well as a few SSNs that have been disallowed since their accidental publishing to the public.
- Parameters:
ssn
- String to check for a valid SSN format.- Returns:
- Boolean indicating whether the given string is a valid SSN.
-
isValidTelephone
Validates a North American Numbering Plan (NANP) telephone number. This does not support international numbers.- Parameters:
phone
- Phone number in string format. Dash-delimited, space-delimited, or no-dash variants are all supported.- Returns:
- Boolean indicating whether the given string is a valid US or North American telephone number.
-
isValidURL
Validates a URL string.- Parameters:
url
- URL in string format. Must include a scheme, such as `http`, `https`, `ftp`, or `file`.- Returns:
- Boolean indicating whether the given string is a valid URL.
-
isValidZipCode
Validates US-only postal codes. Matches 5-digit and 9-digit (ZIP+4) codes, with or without a space or hyphen separator.Beware: This method does not check for zip code ranges or existence. For example, zip codes starting with 429 have not been assigned, and zip codes starting with 987 have been discontinued.
Does not support international postal codes.
- Parameters:
zipCode
- String to check for a valid zip code format.- Returns:
- Boolean indicating whether the given string is a valid zip code.
-
isValidVariableName
Validates a variable name is valid.A valid variable name must start with a letter or underscore, and contain only letters, numbers, and underscores.
- Parameters:
variableName
- String to check for a valid variable name format.- Returns:
- Boolean indicating whether the given string is a valid variable name.
-
isBinary
Verifies if the incoming object is binary or not- Parameters:
value
- The object to check
-
isFloat
Verifies if the incoming object is a float or not- Parameters:
value
- The object to check
-
isBoxClass
Verifies the incoming object is a Box Class- Parameters:
value
- The object to check
-
isFunction
Verifies the incoming object is a Function- Parameters:
value
- The object to check
-
isUDF
Verifies the incoming object is a Function- Parameters:
value
- The object to check
-
isClosure
Verifies the incoming object is a Closure- Parameters:
value
- The object to check
-
isLambda
Verifies the incoming object is a Lambda- Parameters:
value
- The object to check
-
isValidRange
Verifies if the incoming object is within the incoming min and max range- Parameters:
value
- The object to checkmin
- The minimum valuemax
- The maximum value- Returns:
- Boolean indicating if the value is within the range
-
isValidMatch
Verifies if the incoming value matches the passed regular expression- Parameters:
value
- The value to checkregex
- The regular expression to match- Returns:
- Boolean indicating if the value matches the regex
-
isValidMatchNoCase
Verifies if the incoming value matches the passed regular expression without case-sensitivity- Parameters:
value
- The value to checkregex
- The regular expression to match- Returns:
- Boolean indicating if the value matches the regex
-
isValidEmail
Verifies if the incoming object is a valid email address- Parameters:
email
- The email address to validate
-
isValidPattern
Verifies that the incoming string matches the incoming regex pattern- Parameters:
value
- The string to validatepattern
- The regex pattern to match
-