PHP - Function ctype_alnum()


Advertisements


Syntax

ctype_alnum ( $text );

Definition and Usage

It checks if all of the characters in the provided string, text, are alphanumeric. In the standard C locale letters are just [A-Za-z] and the function is equivalent to preg_match('/^[a-z0-9]+$/iD', $text).

Parameters

Sr.No Parameters & Description
1

text(Required)

The tested string.

Return Value

It returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.

Example

Try out following example −

Live Demo
<?php
   $strings = array('hello', 'foo!#$bar');
   
   foreach ($strings as $example) {
      if (ctype_alnum($example)) {
         echo "$example consists of all letters or digits. \n";
      }else {
         echo "$example does not have all letters or digits. \n";
      }
   }
?> 

This will produce the following result −

hello consists of all letters or digits.
foo!#$bar does not have all letters or digits.

php_function_reference.htm

Advertisements