Class ValidationUtil

java.lang.Object
ortus.boxlang.runtime.util.ValidationUtil

public class ValidationUtil extends Object
Utility class for validating user-level data types such as credit cards, postal codes, phone numbers, and URLs. Is not concerned with whether the data is parseable or can be converted to a given type, only whether it is in a valid format.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Verifies if the incoming object is binary or not
    static boolean
    Verifies the incoming object is a Box Class
    static boolean
    Verifies the incoming object is a Closure
    static boolean
    isFloat(Object value)
    Verifies if the incoming object is a float or not
    static boolean
    Verifies the incoming object is a Function
    static boolean
    Verifies the incoming object is a Lambda
    static boolean
    isUDF(Object value)
    Verifies the incoming object is a Function
    static boolean
    Perform the Lunh algorithm to validate a credit card number.
    static boolean
    Verifies if the incoming object is a valid email address
    static boolean
    Validates the given string is a valid Version 4 UUID - in SQL Server, this is known as a GUID.
    static boolean
    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 expression
    static boolean
    Verifies if the incoming value matches the passed regular expression without case-sensitivity
    static boolean
    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 pattern
    static boolean
    isValidRange(Object value, Double min, Double max)
    Verifies if the incoming object is within the incoming min and max range
    static boolean
    Validates a Social Security Number (SSN) in the format of 123-45-6789 or 123456789.
    static boolean
    Validates a North American Numbering Plan (NANP) telephone number.
    static boolean
    Validates a URL string.
    static boolean
    Validates the given string is a valid compatible UUID.
    static boolean
    Validates a variable name is valid.
    static boolean
    Validates US-only postal codes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • URL

      public static final Pattern URL
      Regular expression Pattern to match a URL with a `http`, `https`, `ftp`, or `file` scheme.
    • TELEPHONE

      public static final Pattern TELEPHONE
      Regular expression Pattern to match a North American Numbering Plan (NANP) telephone number. This does not support international numbers.
    • ZIPCODE

      public static final Pattern ZIPCODE
      Regular expression Pattern to match a United States Postal Service (USPS) ZIP Code.
    • SSN

      public static final Pattern SSN
      Regular expression Pattern to match a Social Security Number (SSN).
    • UUID_V4

      public static final Pattern UUID_V4
      Regular expression to match a Version 4 Universally Unique Identifier (UUID), in a case-insensitive fashion.
    • UUID_PATTERN

      public static final Pattern UUID_PATTERN
      Regular expression to match a Version 4 Universally Unique Identifier (UUID), in a case-insensitive fashion.
    • VALID_VARIABLE_REGEX

      public static final String VALID_VARIABLE_REGEX
      Regular expression to match a valid variable name.
      See Also:
  • Constructor Details

    • ValidationUtil

      public ValidationUtil()
  • Method Details

    • isValidCreditCard

      public static boolean isValidCreditCard(String cardNumber)
      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

      public static boolean isValidInteger(Object value)
      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

      public static boolean isValidNumeric(Object value)
      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

      public static boolean isValidGUID(String uuid)
      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, use isValidUUID(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

      public static boolean isValidUUID(String uuid)
      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

      public static boolean isValidSSN(String ssn)
      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

      public static boolean isValidTelephone(String phone)
      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

      public static boolean isValidURL(String url)
      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

      public static boolean isValidZipCode(String zipCode)
      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

      public static boolean isValidVariableName(String variableName)
      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

      public static boolean isBinary(Object value)
      Verifies if the incoming object is binary or not
      Parameters:
      value - The object to check
    • isFloat

      public static boolean isFloat(Object value)
      Verifies if the incoming object is a float or not
      Parameters:
      value - The object to check
    • isBoxClass

      public static boolean isBoxClass(Object value)
      Verifies the incoming object is a Box Class
      Parameters:
      value - The object to check
    • isFunction

      public static boolean isFunction(Object value)
      Verifies the incoming object is a Function
      Parameters:
      value - The object to check
    • isUDF

      public static boolean isUDF(Object value)
      Verifies the incoming object is a Function
      Parameters:
      value - The object to check
    • isClosure

      public static boolean isClosure(Object value)
      Verifies the incoming object is a Closure
      Parameters:
      value - The object to check
    • isLambda

      public static boolean isLambda(Object value)
      Verifies the incoming object is a Lambda
      Parameters:
      value - The object to check
    • isValidRange

      public static boolean isValidRange(Object value, Double min, Double max)
      Verifies if the incoming object is within the incoming min and max range
      Parameters:
      value - The object to check
      min - The minimum value
      max - The maximum value
      Returns:
      Boolean indicating if the value is within the range
    • isValidMatch

      public static boolean isValidMatch(String value, String regex)
      Verifies if the incoming value matches the passed regular expression
      Parameters:
      value - The value to check
      regex - The regular expression to match
      Returns:
      Boolean indicating if the value matches the regex
    • isValidMatchNoCase

      public static boolean isValidMatchNoCase(String value, String regex)
      Verifies if the incoming value matches the passed regular expression without case-sensitivity
      Parameters:
      value - The value to check
      regex - The regular expression to match
      Returns:
      Boolean indicating if the value matches the regex
    • isValidEmail

      public static boolean isValidEmail(String email)
      Verifies if the incoming object is a valid email address
      Parameters:
      email - The email address to validate
    • isValidPattern

      public static boolean isValidPattern(String value, String pattern)
      Verifies that the incoming string matches the incoming regex pattern
      Parameters:
      value - The string to validate
      pattern - The regex pattern to match