Check For Alphanumeric characters

This example checks for alphanumeric charcters which in this case are lower case and upper case letters and the numbers 0 to 9 using regular expressions

<?php
// sample strings
$string1 = “abc123”;
$string2 = “abc123-+/~”;
//check string 1
if (ereg(‘[^A-Za-z0-9]’, $string1))
{
  echo “non alphanumeric”;
}
else
{
  echo “alphanumeric”;   
}
//check string2
if (ereg(‘[^A-Za-z0-9]’, $string2))
{
  echo “non alphanumeric”;
}
else
{
  echo “alphanumeric”;   
}

?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*