Mega Code Archive

 
Categories / Php / Code Snippets
 

Verify using ereg that characters in a variable only contain numbers

<?php // Example 1$text = "012345";if (ereg('[^0-9]', $text)) { echo "This contains characters other than just numbers";} else { echo "This contains only numbers"; } // Example 2$text = "mixedcharacters012345&../@"; if (ereg('[^A-Za-z0-9]', $text)) { echo "This contains characters other than just numbers";} else { echo "This contains only numbers"; } ?>