Copyright © tutorialspoint.com

PHP Function ctype_digit()

previous
Advertisements

Syntax

ctype_digit ( $text );

Definition and Usage

Checks if all of the characters in the provided string, text, are numerical. It checks only 1...9

Paramters

ParameterDescription
textRequired. The tested string.

Return Value

Returns TRUE if every character in text is a decimal digit, FALSE otherwise.

Example

Try out following example:

<?php
$strings = array('122.50', '1004', 'foo!#$bar');
foreach ($strings as $testcase) {
 if (ctype_digit($testcase)) {
     echo "$testcase consists of all digits.<br />";
 } else {
     echo "$testcase does not have all digits.<br />";
 }
}
?> 

This will produce following result:

122.50 does not have all digits
1004 consists of all digits
foo!#$bar does not have all digits
previous

Copyright © tutorialspoint.com