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