Mega Code Archive

 
Categories / Php / Code Snippets
 

Use ereg to check that characters in a variable only contain letters

<?php // Example 1$text = "onlytextcharacters"; if (ereg('[^A-Za-z]', $text)) { echo "This contains characters other than just letters"; } else { echo "This contains only letters"; } // Example 2$text = "mixedcharacters012*&.@"; if (ereg('[^A-Za-z]', $text)) { echo "This contains characters other than just letters";} else { echo "This contains only letters"; } ?>