Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
IntlChar::isalnum() function in PHP
The IntlChar::isalnum() function is used to check whether a given input character is alphanumeric or not. An alphanumeric character is either a digit (0-9) or a letter (A-Z, a-z).
Syntax
bool IntlChar::isalnum(mixed $codepoint)
Parameters
codepoint − An integer value or a single character encoded as a UTF-8 string to check.
Return Value
The IntlChar::isalnum() function returns TRUE if the codepoint is an alphanumeric character, FALSE otherwise, or NULL on failure.
Example 1
The following example demonstrates checking various characters ?
<?php
var_dump(IntlChar::isalnum("A"));
echo "<br>";
var_dump(IntlChar::isalnum("5"));
echo "<br>";
var_dump(IntlChar::isalnum("$"));
echo "<br>";
var_dump(IntlChar::isalnum("z"));
echo "<br>";
var_dump(IntlChar::isalnum("0"));
?>
bool(true) bool(true) bool(false) bool(true) bool(true)
Example 2
Testing with Unicode codepoints and special characters ?
<?php
var_dump(IntlChar::isalnum("#"));
echo "<br>";
var_dump(IntlChar::isalnum("1"));
echo "<br>";
var_dump(IntlChar::isalnum(65)); // ASCII code for 'A'
echo "<br>";
var_dump(IntlChar::isalnum(48)); // ASCII code for '0'
?>
bool(false) bool(true) bool(true) bool(true)
Key Points
The function only works with single characters, not strings
Returns
NULLwhen passed multi-character stringsAccepts both character literals and Unicode codepoints as integers
Part of the PHP Intl extension for internationalization support
Conclusion
The IntlChar::isalnum() function provides a reliable way to check if a single character is alphanumeric. It's particularly useful for input validation and character classification in internationalized applications.
