PHP - Function ctype_alnum()


Advertisements


Syntax

ctype_alnum ( $text );

Definition and Usage

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

Parameter Description
text Required. The tested string.

Return Value

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

Example

Try out following example −

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

This will produce the following result −

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

php_function_reference.htm

Advertisements