-1

I would like to know how can I check if a variable contains numbers 0 to 9 and characters a to z, like that:

 if($string contains numbers[0-9] and characters[a-z])
 {
  echo "true";
} else {echo "false";}

1 Answers1

4

You can use regex. preg_match

$str = "aab1230";
if(preg_match('/^[0-9a-z]+$/', $str)) {
   // contains only characters [0-9] and/or [a-z]
}
user1759572
  • 683
  • 4
  • 11