$strs = [];
$strs[] = "abc-123_5.csv";
$strs[] = "ねこ";
$strs[] = "cat";
$strs[] = 987;
$strs[] = "";
$strs[] = '-_';
$strs[] = 'abcあ';
foreach($strs as $str){
echo $str;
if (preg_match("/^[a-zA-Z0-9-_.]+$/", $str)) {
echo "¥t〇<br>";
} else {
echo "¥t×<br>";
}
}
出力
abc-123_5.csv 〇
ねこ ×
cat 〇
987 〇
×
-_ 〇
abcあ ×