Predicate function - Text

The text functions are used for validating string content, format, patterns, and character composition.

  • Unless explicitly stated, predicates operate on string inputs only.

  • Non-string values (null, undefined, objects, arrays, dates) return false.

  • Null, empty strings (" "), and whitespace-only strings are treated distinctly.

  • Text predicates are case-sensitive by default and support Unicode where applicable.

Function

Description

Example

IsText(value) Returns true if the value is a text/string.

  • "hello" is true

  • " " is true

  • 123 is false

  • null is false

IsEmpty(value) Returns true if the value is an empty string (zero length).

  • "" is true

  • null is true

  • "\t" is false

  • "hello" is false

IsNotEmpty(value) Returns true if the text is not empty.

  • "hello" is true

  • " " is true

  • null is false

  • 123 is false

IsNull(value) Returns true if the value is null

  • null is true

  • DBNull.Value (C#) is true

  • 0 is false

  • undefined is false

IsNotNull(value) Returns true if the value is not null.

  • "hello" is true

  • 0 is true

  • null is false

IsNullOrEmpty(value) Returns true if the text is null or empty.

  • null is true

  • "" is true

  • " " is false

  • undefined is false

IsNullOrWhiteSpace(value) Returns true if the text is null, empty, or contains only whitespace.

  • null is true

  • " \t \n " is true

  • "hello" is true

  • undefined is false

IsAlpha(value) Returns true if the text contains only alphabetic characters.

  • "hello" is true

  • "abcXYZ" is true

  • " hello123" is false

  • "hello!" false

IsAlphanumeric(value) Returns true if the text contains only letters and numbers.

  • "a1b2c3" is true

  • "ABC" is true

  • "test_123" is false

  • "hello!" false

IsNumericString(value) Returns true if the text contains only numeric characters.

  • "123" is true

  • "0123456789" is true

  • "123.45" is false

  • "-123" is false

IsUpperCase(value) Returns true if all letters in the text are uppercase.

  • "HELLO" is true

  • "ABC-123" is true

  • "Hello" is false

IsLowerCase(value) Returns true if all letters in the text are lowercase.

  • "hello" is true

  • "abc-123" is true

  • "Hello" is false

IsMixedCase(value) Returns true if the text contains both uppercase and lowercase letters.

  • "Hello" is true

  • "ABC123abc" is true

  • "hello" is false

IsTrimmed(value) Returns true if the text has no leading or trailing whitespace.

  • "hello" is true

  • "a b c" is true

  • (" hello") is false

  • ("hello\n") is true

ContainsLetters(value) Returns true if the text contains at least one letter.

  • "abc123" is true

  • "!!!hello!!!" is true

  • "123" is false

  • "!@#" is false

ContainsDigits(value) Returns true if the text contains at least one digit.

  • "abc1def" is true

  • "hello" is fa

ContainsWhitespace(value) Returns true if the text contains whitespace characters.

  • >

    "hello world" is true

  • "hello" is false

HasSpecialCharacters(value) Returns true if the text contains at least one special character (non-alphanumeric, non-whitespace).

  • "hello!" is true

  • "50%" is tue

  • "123" is false

  • "hello world" is false

IsMinimumLength(value, length) Returns true if the text length is greater than or equal to a minimum length.

  • IsMinimumLength("hello", 3) is true

  • IsMinimumLength("hi", 3) is false

IsMaximumLength(value, length) Returns true if the text length is less than or equal to a maximum length.

  • IsMaximumLength("hello", 5) is true

  • IsMaximumLength("hello", 3) is false

IsExactLength(value, length) Returns true if the text length exactly matches the specified length.

  • IsExactLength("test", 4) is true

  • IsExactLength("test", 5) is false

IsLengthBetween(value, min, max) Returns true if the text length is between the minimum and the maximum range.

  • IsLengthBetween("hello", 3, 10) is true

  • IsLengthBetween("hi", 3, 10) is false

MatchesPattern(value, pattern) Returns true if the text matches the specified regular expression pattern.

  • MatchesPattern("abc123", "^[a-z]+[0-9]+$") is true

  • MatchesPattern("abc", "^[0-9]+$") is false

DoesNotMatchPattern(value, pattern) Returns true if the text does not match the specified regular expression pattern.

  • DoesNotMatchPattern("abc", "^[0-9]+$") is true

  • DoesNotMatchPattern("123", "^[0-9]+$") is false

IsPalindrome(value) Returns true if the text is palindrome (reads the same forwards and backwards).

  • "racecar" is true

  • "A" is true

  • "hello" is false

  • "race car" is false

HasConsecutiveCharacters(value, count) Returns true if the text has a specified number of consecutive identical characters.

  • HasConsecutiveCharacters("hello", 2) is true

  • HasConsecutiveCharacters("aaa", 3) is true

  • HasConsecutiveCharacters("test", 2) is false

  • HasConsecutiveCharacters("aa", 1) is false

Contains(substring, value) Returns true if the text contains the specified substring.

  • Contains("hello world", "world") is true

  • Contains("hello", "x") is false

ContainsLetter(value, letter) Returns true if the text contains the specified letter.

  • ContainsLetter("hello", "h") is true

  • ContainsLetter("123", "1") is false

ContainsSpecialCharacter(value, character) Returns true if the text contains the specified special character.

  • ContainsSpecialCharacter("hello!", "!") is true

  • ContainsSpecialCharacter("hello", "!") is false

StartsWith(value, substring) Returns true if the text starts with the specified substring.

  • StartsWith("hello", "he") is true

  • StartsWith("hello", "el") is false

StartsWithLetter(value, letter) Returns true if the text starts with the specified letter.

  • StartsWithLetter("hello", "h") is true

  • StartsWithLetter("hello", "e") is false

  • StartsWithLetter("123test", "1") is false

StartsWithNumber(value, number) Returns true if the text starts with the specified number.

  • StartsWithNumber("123test", "1") is true

  • StartsWithNumber("test123", "1") is false

  • StartsWithNumber("hello", "h") is false

EndsWith(value, substring) Returns true if the text ends with the specified substring.

  • EndsWith("hello world", "world") is true

  • EndsWith("hello", "hell") is false

  • EndsWith ("test", "Test") is false

EndsWithLetter(value, letter) Returns true if the text ends with the specified letter.

  • EndsWithLetter("hello", "o") is true

  • EndsWithLetter("hello", "e") is false

  • EndsWithLetter("test123", "3") is false

EndsWithNumber(value, number) Returns true if the text ends with the specified number.

  • EndsWithNumber("test123", "3") is true

  • EndsWithNumber("123test", "3") is false

  • EndsWithNumber("hello", "o") is false

IsEmail(value) Returns true if the text is a valid email address format.

  • "test@example.com" is true

  • "test@example" is false

  • "test @example.com" is false

IsPhoneNumber(value) Returns true if the text is a valid phone number format (generic, various formats).

  • "(123) 456-7890" is true

  • "+44 20 1234 5678" is true

  • "123-abc-7890" is false

IsUSPhoneNumber(value) Returns true if the text is a valid US phone number format (10 digits).

  • "+1-123-456-7890" is true

  • "(123) 456-7890" is true

  • "123-456-789" is false

IsURL(value) Returns true if the text is a valid URL format.

  • "https://example.com:8080/path?query=1" is true

  • "ftp://ftp.example.com" is true

  • "example.com" is false

IsIPAddress(value) Returns true if the text is a valid IP address (IPv4 or IPv6).

  • "192.168.1.1" is true

  • "2001:0db8:85a3:0000:0000:8a2e:0370:7334" is true

  • "abc" is false

IsIPv4(value) Returns true if the text is a valid IPv4 address.

  • "10.0.0.1" is true

  • "::1" is false (IPv6)

IsIPv6(value) Returns true if the text is a valid IPv6 address.

  • "::1" is true

  • "gggg::1" is false

  • "192.168.1.1" is false (IPv4)

IsUSZipCode(value) Returns true if the text is a valid US ZIP code (5 digits or ZIP+4 format).

  • "12345-6789" is true

  • "12345-678" is false

  • "1234" is false

IsUKPostcode(value) Returns true if the text is a valid UK postcode format.

  • "DN55 1PT" is true

  • "12345" is false (US ZIP)

IsSSN(value) Returns true if the text is a valid Social Security Number format (XXX-XX-XXXX).

  • "111-11-1111" is true

  • "123-45-678" is false

IsGUID(value) Returns true if the text is a valid GUID/UUID format.

  • "550E8400-E29B-41D4-A716-446655440000" is true

  • "550e8400" is false (incomplete)

IsHexColor(value) Returns true if the text is a valid hexadecimal color code (#RGB or #RRGGBB).

  • "#FFF" is true

  • "#GGGGGG" is false (invalid hex)

IsJSON(value) Returns true if the text is a valid JSON format.

  • "{\"key\":\"value\"}" is true

  • "{'key':'value'}" is false (single quotes)

ISBase64(value) Returns true if the text is valid Base64 encoded data.

  • "base64==" is true (with padding)

  • "Hello World" is false (not encoded)