testing whether a value is alpha-numeric
Posted: Wed Jun 07, 2006 6:29 pm
Is there a function that tests whether a value is an alpha-numeric string? I looked on php.net but couldn't find one. Am I going to have to use regex?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
// Example 1
$text = "onlyalphanumericcharacters012345";
if (ereg('[^A-Za-z0-9]', $text)) {
echo "This contains characters other than letters and numbers";
}
else {
echo "This contains only letters and numbers";
}
// Example 2
$text = "mixedcharacters012345&../@";
if (ereg('[^A-Za-z0-9]', $text)) {
echo "This contains characters other than letters and numbers";
}
else {
echo "This contains only letters and numbers";
}
?>