Вы можете использовать:
// returns true if $str has a whitespace(space, tab, newline..) anywhere in it.
function has_whitespace($str) {
return preg_match('/\s/',$str);
}
Или вы можете написать свою собственную функцию, чтобы проверить, содержит ли строка только алфавиты, цифры, пробелы:
// returns true if $str has nothing but alphabets,digits and spaces.
function is_alnumspace($str){
return preg_match('/^[a-z0-9 ]+$/i',$str);
}