Full unit testing list
This page provides a complete list of all available validation methods in PHP Unitary. Each method includes a short description and usage example to help you quickly find and apply the right validator for your data.
Use this as your go-to guide when building or reviewing your validation logic.
Navigation
length
Validates that the length of a string is greater than or equal to a specified minimum. Optionally, a maximum length can be provided to ensure the string length falls within a defined range.
isRequired
Validates that a value is present and not empty. Returns false for empty strings, null, zero, or other empty values. Commonly used to ensure a required field has been filled in.
isTrue
Performs a strict comparison to check if the value is exactly true. This validation does not allow truthy values such as 1, 'true', or other equivalents—only the boolean true is accepted.
isTruthy
Checks if the value is considered truthy. Accepts values such as true, 1, '1', 'true', 'on', and 'yes' as valid. Uses PHP's filter_var() with FILTER_VALIDATE_BOOLEAN, making it a flexible boolean check.
isFalse
Performs a strict comparison to check if the value is exactly false. This validation does not accept falsy values such as 0, 'false', or null—only the boolean false is considered valid.
isFalsy
Checks if the value is considered falsy. Accepts values such as false, 0, '0', 'false', 'off', and 'no' as valid falsy inputs. Uses PHP's filter_var() with FILTER_VALIDATE_BOOLEAN for flexible boolean validation.
isInArray
Checks if a specified value exists within the provided array. This method performs a strict type comparison, ensuring that both the value and its type match exactly.
isLooselyInArray
Checks if a specified value exists within the provided array using loose comparison. Type matching is not required, allowing values like 0 and '0' to be treated as equal.
hasValueAt
Traverses an array or object using a dot-notated key path and validates that the value at the specified path is strictly equal (===) to the expected value. Supports deep access into nested structures (e.g., user.firstname) and works with both arrays and objects.
hasJsonValueAt
Traverses an array or object using a dot-notated key path and validates that the value at the specified path is strictly equal (===) to the expected value. Supports deep access into nested structures (e.g., user.firstname) and works with both arrays and objects.
keyExists
Checks if a specified key exists in the array. This validation first ensures the value is an array, then uses array_key_exists() to verify the presence of the given key.
hasValue
Checks whether the value contains at least one character. This validation does not consider the content, only that something is present (i.e. not an empty string).
isSocialNumber
Validates a personal identity number (personnummer). The value must follow the correct format and pass both the Luhn algorithm and the specific rules for Swedish social numbers. The Luhn algorithm is also commonly used in social security or identification numbers in countries like Norway, Swedish, Finland, and Denmark, although formats and validation rules may differ slightly.
isOrgNumber
Validates a organization number (organisationsnummer). The value must follow the correct structure and pass the Luhn algorithm, which is used to ensure the number’s integrity. The Luhn algorithm is also used for validating similar types of registration or identification numbers in other countries, including Sweden (organisationsnummer), Norway (organisasjonsnummer), Finland (y-tunnus), and Denmark (CVR-nummer), although the formatting rules may differ.
isVatNumber
Validates a VAT number. The value must follow the correct format and pass the Luhn algorithm check for nordic countries, including Swedish (momsregistreringsnummer), Norway (MVA-nummer), Finland (ALV-numero), and Denmark (Momsnummer), although exact formats and rules vary. Other EU countries uses unique patterns to for each country to validate VAT numbers.
isCreditCard
Validates a credit card number by checking both the number format and applying the Luhn algorithm. This method supports most major card types including Visa, MasterCard, American Express, and others that follow Luhn validation rules. Note: Actual card brand detection is not performed—only structural and checksum validation.
isEmail
Validates that the value is a properly formatted email address. This ensures the syntax follows standard email conventions (e.g. user@example.com).
isDeliverableEmail
Validates whether an email address is potentially deliverable. This checks both the syntax of the email address using standard email validation, and verifies that the domain has a valid MX (Mail Exchange) DNS record. This helps ensure that the email address is not only well-formed but also points to a mail-receiving server.
contains
Checks if the string contains the given substring anywhere within it. This is a simple case-sensitive check using PHP’s str_contains() function.
startsWith
Checks if the string starts with the given substring. This is a case-sensitive match using PHP’s str_starts_with() function.
endsWith
Checks if the string ends with the given substring. This is a case-sensitive match using PHP’s str_ends_with() function.
isPhone
Validates if the value is a valid phone number. This method removes common separators like spaces, dashes, and parentheses before checking the format. It supports both flexible phone numbers with 7–14 digits and strict international numbers starting with a + followed by 7–15 digits.
isZip
Validates if the value is a ZIP or postal code by first removing spaces and common dash characters, then checking if it's an integer and if its length matches the expected range. This method supports country-specific formatting by accepting a minimum and optional maximum length.
isFloat
Validates whether the value is a valid float. Common for validating decimal numbers, even when passed as strings (e.g., from form input).
isInt
Validates whether the value is a valid integer. Useful for checking numeric input, even when the value is submitted as a string.
isString
Checks if the value is of type string. This does not cast values; it strictly checks the data type.
isArray
Checks if the value is an array. Does not validate JSON or comma-separated strings—only PHP arrays.
isObject
Checks if the value is an object. Useful for validating instances, configurations, or dynamic data structures.
isResource
Checks if the value is a valid PHP resource (e.g., file handles, database connections).
isNull
Checks if the value is strictly null. This validation only passes when the value is exactly null, not when it is an empty string, false, or any other falsy value.
isFullHtml
Checks if the string is a complete HTML document. Must include doctype, <html>, <head>, and <body> tags.
isDir
Checks if the given value is a valid directory path. Returns true only if the path exists and is recognized as a directory by the filesystem.
isFile
Checks if the given value is a valid file path. Returns true only if the path exists and is recognized as a file by the filesystem (not a directory).
isFileOrDirectory
Checks whether the given value is a valid path to an existing file or directory. Uses PHP's file_exists() to determine the existence of the file system resource.
isWritable
Checks whether the given path is writable. This includes files and directories that the current process has permission to write to, using PHP's is_writable() function.
isReadable
Checks whether the given path is readable. Applies to both files and directories, using PHP's is_readable() function to determine if the current process has read permissions.
isNumber
Validates that the value is strictly a number, either an integer or a floating-point number. This check does not accept numeric strings—only actual numeric types are considered valid.
isNumbery
Checks if the value is numeric in a loose sense. Accepts numeric strings (e.g. '42', '3.14'), integers, floats, and scientific notation (e.g. '1e4'). Uses PHP’s is_numeric() function.
isPositive
Checks if the value is a positive number, including zero. Accepts both integers and floats, as well as numeric strings that can be cast to a float.
isNegative
Checks if the value is a negative number. Accepts both integers and floats, as well as numeric strings that can be cast to a float. Zero and positive values are not considered valid.
min
Validates that the value is greater than or equal to the given minimum number. Accepts integers, floats, and numeric strings that can be cast to a float.
max
Validates that the value is less than or equal to the given maximum number. Accepts integers, floats, and numeric strings that can be cast to a float.
isArrayEmpty
Checks whether the value is an array and that it contains no elements. Returns true only if the value is an array and its length is zero.
itemsAreTruthy
Checks whether all items in an array have a truthy value for the specified key. Each item is expected to be an object or structure where the given key exists. The check uses flexible boolean validation (truthy values such as true, 1, 'yes', etc.).
hasTruthyItem
Checks if an array contains at least one item where the specified key holds a truthy value. The value at the key is evaluated using flexible boolean validation (e.g. true, 1, 'yes', 'on', etc.).
isCountEqualTo
Validates that the given value is an array and that the number of items in the array is exactly equal to the specified length.
isCountMoreThan
Validates that the given value is an array and contains more items than the specified number.
isCountLessThan
Validates that the given value is an array and contains fewer items than the specified number.
isLengthEqualTo
Validates that the length of a string is exactly equal to the specified number of characters.
isEqualTo
Performs a strict comparison to check if the value is exactly equal to the expected value. Both type and value must match.
isLooselyEqualTo
Checks if the value is loosely equal to the expected value. Type juggling is allowed in the comparison.
isNotEqualTo
Performs a strict comparison to check if the value is not equal to the provided value. Both type and value must differ.
isLooselyNotEqualTo
Performs a loose comparison to check if the value is not equal to the provided value. Type differences are allowed.
isInstanceOf
Checks whether the value is an instance of a specified class or implements a given interface. This validation performs a strict type check using PHP's instanceof operator.
isClass
Validates that the given value is exactly an instance of the specified class, or a matching class name string. This is a strict comparison and does not allow inheritance or interface checks—only exact class matches are accepted.
isLessThan
Checks if the current value is numerically less than the given number.
isGreaterThan
Checks if the current value is numerically greater than the given number.
isAtLeast
Checks if the value is greater than or equal to the specified number. Useful for setting a lower bound in numeric validations.
isAtMost
Checks if the value is less than or equal to the specified number. Useful for setting an upper bound in numeric validations.
isValidVersion
Checks if the value is a valid version number. When strict mode is enabled, it requires Semantic Versioning format (e.g. 1.0.0).
versionCompare
Compares the current version against another using a specified comparison operator. Supports all standard version_compare operators.
isLossyPassword
Checks if the value is a valid password containing only allowed characters (letters, digits, and special characters). Does not require specific character types.
isStrictPassword
Validates that the password includes at least one lowercase letter, one uppercase letter, one digit, and one special character. Recommended to combine with @length(8, 60) for complete strength validation.
isMatchingPattern
Validates that the value contains only characters from the specified character range pattern. Useful for custom character restrictions.
isAlpha
Checks if the value contains only alphabetic characters (both lowercase and uppercase letters).
isLowerAlpha
Checks if the value contains only lowercase alphabetic characters (a–z).
isUpperAlpha
Checks if the value contains only uppercase alphabetic characters (A–Z).
isHexColor
Checks if the value is a valid hexadecimal color code (e.g., #fff or #ffffff).
isHexString
Validates that the value is a valid hexadecimal string. The string must contain only characters 0–9 and a–f (case-insensitive). An optional length can be specified to enforce an exact character count.
isDate
Validates that the value matches a date in a specific format. The default format is Y-m-d (e.g., '2025-04-22').
isDateWithTime
Checks if the value is a valid date and time in the format Y-m-d H:i:s.
isTime
Checks if the value is a valid time. By default, the format is H:i. Set $withSeconds to true to validate H:i:s.
isAge
Validates that a date-based value corresponds to a minimum age. The value must be a valid date string in Y-m-d format, representing a birthdate. The method calculates the age based on the current year.
isDomain
Validates that the value is a syntactically valid domain name. Optionally enforces stricter checks using FILTER_FLAG_HOSTNAME.
isUrl
Checks if the value is a valid URL starting with http or https. This method uses PHP’s FILTER_VALIDATE_URL.
isResolvableHost
Validates whether a domain or host has a valid DNS record. This includes checking A, AAAA, or MX records.
isHttpStatusCode
Checks if the value is one of the officially recognized HTTP status codes (e.g., 200, 404, 500).
isHttp200
Strictly validates that the value is the HTTP 200 OK status code.
isHttpSuccess
Checks if the value is a 2xx range HTTP status code, indicating a successful response.
isHttpClientError
Checks if the value is a 4xx range HTTP status code, indicating a client-side error.
isHttpServerError
Checks if the value is a 5xx range HTTP status code, indicating a server-side error.
isRequestMethod
Validates whether the given string is a valid HTTP request method. Accepted methods include: GET, POST, PUT, DELETE, PATCH, HEAD, and OPTIONS. The check is case-sensitive and only matches exact method names.
hasKey
Checks whether a specific key exists in the given array or object without flattening the structure. This method uses a deep traversal that respects nested hierarchies without merging keys into dot notation.
hasFlattenKey
Checks whether a specific key exists in a flattened version of an array or object. The structure is flattened into dot notation before the key check is performed, allowing nested keys to be accessed as a flat path.
oneOf
Validates the value against multiple methods and returns true if at least one validation passes. Useful for conditional validation rules.
allOf
Validates the value against multiple methods and returns true only if all validations pass. Useful for combining multiple rules into one check.
findInString
Checks whether the given substring exists within the value. By default, it returns true if the substring is found anywhere in the string. Optionally, you can provide a position to check if the substring appears at a specific index.
isResolvableHost
Checks if a domain or host is resolvable via DNS. It validates whether an MX record (mail exchange) or an address record (A or AAAA) exists for the host.
isAddressRecord
Checks if a domain has a valid A or AAAA DNS record. An A record maps a domain to an IPv4 address, and an AAAA record maps it to an IPv6 address.
isMxRecord
Checks if a domain has a valid MX (Mail Exchange) DNS record. MX records are used to route emails to the correct mail server for the domain.
isCnameRecord
Checks if a domain has a valid CNAME (Canonical Name) DNS record. A CNAME record aliases one domain to another, allowing multiple domains to point to the same destination.
isARecord
Checks if a domain has a valid A record in DNS. An A record maps a domain name to its corresponding IPv4 address, enabling resolution to an IP address.
isAaaaRecord
Checks if a domain has a valid AAAA record in DNS. An AAAA record maps a domain name to its corresponding IPv6 address.
isNsRecord
Checks if a domain has a valid NS (Name Server) DNS record. NS records specify the authoritative name servers responsible for the domain.
isSoaRecord
Checks if a domain has a 'SOA' (Start of Authority) DNS record. The SOA record contains administrative information about the domain, such as the primary DNS server and administrator contact details.
isTxtRecord
Checks if a domain has a 'TXT' DNS record. TXT records are used to store text information such as SPF records or other human-readable data linked to the domain.
isSrvRecord
Checks if a domain has an 'SRV' DNS record. SRV records define the location (hostname and port) of servers for specified services.
isNaptrRecord
Checks if a domain has a 'NAPTR' (Naming Authority Pointer) DNS record. NAPTR records are used to map services like phone numbers to domain names or define service-specific rules.
isA6Record
Checks if a domain has an 'A6' DNS record. A6 records were used for IPv6 addresses but are now deprecated in favor of AAAA records.
isAnyRecord
Checks if a domain has any type of DNS record. It validates whether at least one DNS record of any kind exists for the host.
isAllRecord
Attempts to check if a domain has all possible DNS record types (A, AAAA, CNAME, NS, SOA, etc.). Note: Not all record types may exist for every domain.
isCaaRecord
Checks if a domain has a 'CAA' (Certification Authority Authorization) DNS record. CAA records define which certificate authorities are permitted to issue SSL/TLS certificates for the domain.
isPtrRecord
Checks if a domain has a 'PTR' (Pointer) DNS record. PTR records are used for reverse DNS lookups, mapping IP addresses back to hostnames.
isHinfoRecord
Checks if a domain has an 'HINFO' (Host Information) DNS record. HINFO records describe the host’s hardware and operating system, though they are rarely used today due to security concerns.