The Str class provides various static methods for checking the characteristics of strings. Below is the documentation for each available method.
isAlphanumericChecks if a string contains only alphanumeric characters (letters and numbers).
string $string: The string to check.bool: True if the string is alphanumeric, false otherwise.use App\Helpers\Str;
$result = Str::isAlphanumeric('abc123'); // True
$result = Str::isAlphanumeric('abc 123'); // False
isAlphaChecks if a string contains only alphabetic characters (letters).
string $string: The string to check.bool: True if the string is alphabetic, false otherwise.use App\Helpers\Str;
$result = Str::isAlpha('abc'); // True
$result = Str::isAlpha('abc123'); // False
isControlChecks if a string contains control characters.
string $string: The string to check.bool: True if the string contains control characters, false otherwise.use App\Helpers\Str;
$result = Str::isControl("\n\r"); // True
$result = Str::isControl('abc'); // False
isDigitChecks if a string contains only numeric characters (digits).
string $string: The string to check.bool: True if the string contains only numeric characters, false otherwise.use App\Helpers\Str;
$result = Str::isDigit('12345'); // True
$result = Str::isDigit('123a45'); // False
isGraphChecks if a string contains only printable characters excluding spaces.
string $string: The string to check.bool: True if the string contains only printable characters excluding spaces, false otherwise.use App\Helpers\Str;
$result = Str::isGraph('abc123!@#'); // True
$result = Str::isGraph('abc 123'); // False
isLowerChecks if a string contains only lowercase alphabetic characters.
string $string: The string to check.bool: True if the string contains only lowercase characters, false otherwise.use App\Helpers\Str;
$result = Str::isLower('abc'); // True
$result = Str::isLower('Abc'); // False
isPrintChecks if a string contains only printable characters.
string $string: The string to check.bool: True if the string contains only printable characters, false otherwise.use App\Helpers\Str;
$result = Str::isPrint('abc123'); // True
$result = Str::isPrint("abc\n123"); // False
isPunctChecks if a string contains only printable characters that are neither spaces nor alphanumeric.
string $string: The string to check.bool: True if the string contains only punctuation characters, false otherwise.use App\Helpers\Str;
$result = Str::isPunct('!@#'); // True
$result = Str::isPunct('abc!'); // False
isSpaceChecks if a string contains only whitespace characters.
string $string: The string to check.bool: True if the string contains only whitespace characters, false otherwise.use App\Helpers\Str;
$result = Str::isSpace(' '); // True
$result = Str::isSpace('abc'); // False
isUpperChecks if a string contains only uppercase alphabetic characters.
string $string: The string to check.bool: True if the string contains only uppercase characters, false otherwise.use App\Helpers\Str;
$result = Str::isUpper('ABC'); // True
$result = Str::isUpper('Abc'); // False
isHexChecks if a string contains only hexadecimal characters (digits 0-9 and letters A-F/a-f).
string $string: The string to check.bool: True if the string contains only hexadecimal characters, false otherwise.use App\Helpers\Str;
$result = Str::isHex('1a2b3c'); // True
$result = Str::isHex('1g2h3i'); // False