testing whether a value is alpha-numeric
Moderator: General Moderators
testing whether a value is alpha-numeric
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?
oh google how I love thee
http://www.totallyphp.co.uk/code/check_ ... g_ereg.htm
http://www.totallyphp.co.uk/code/check_ ... g_ereg.htm
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";
}
?>- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US