Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function ctype_alnum()


previous

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).

Paramters

ParameterDescription
textRequired. 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.<br />";
 } else {
     echo "$testcase does not have all letters or digits.<br />";
 }
}
?> 

This will produce following result:

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

previous Printer Friendly

Advertisements


  

Advertisements