Saturday, February 7, 2026
HomeLanguagesPHP | ctype_alnum() (Check for Alphanumeric)

PHP | ctype_alnum() (Check for Alphanumeric)

A ctype_alnum() function in PHP used to check all characters of given string/text are alphanumeric or not. If all characters are alphanumeric then return TRUE, otherwise return FALSE. Syntax:

 bool ctype_alnum ($text)

Parameters Used:

  • $text : It is a mandatory parameter which specifies the string.

Examples:

Input  : Geeks
Output : Yes
Explanation : String "Geeks" is alphanumeric.
              Note: Read Standard c local letter.
      
Input  : '%%%Contribute_article on GFG!!!'
Output : No
         
Explanation : String contains Special characters.
                 
Note: Except string or digit, if we input anything then it will return FALSE.

Below programs illustrate the ctype_alnum() function. Program :1 Drive a code ctype_alnum()() function for better understand. 

PHP




<?php
 
// PHP program to check given string is
// all characters are alphanumeric
 
$string = 'neveropen';
 
    if ( ctype_alnum($string))
        echo "Yes\n";
    else
        echo "No\n";
 
?>


Output:

Yes

Program: 2 Drive a code of ctype_alnum() function where input will be an array of string integers, string with special symbols. 

PHP




<?php
// PHP program to check given string is
// all characters are alphanumeric
 
$strings = array(
    'Geeks',
    'geek@gmail.com',
    '2018',
    'GFG2018',
    'a b c ',
    '@!$%^&*()|2018'
);
 
// Checking above given four strings
// by used of  ctype_alnum() function .
foreach ($strings as $test) {
     
    if (ctype_alnum($test))
        echo "Yes\n";
    else
        echo "No\n";
     
}
 
?>


Output:

Yes
No
Yes
Yes
No
No

References :http://php.net/manual/en/function.ctype-alnum.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32491 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11987 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12075 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7237 POSTS0 COMMENTS
Thapelo Manthata
6947 POSTS0 COMMENTS
Umr Jansen
6933 POSTS0 COMMENTS