-2

我想知道如何检查变量是否包含数字 0 到 9 和字符 a 到 z,如下所示:

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

1 回答 1

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]
}
于 2013-07-14T21:30:09.363 回答