- preg_match: documentation ( source)
<?php
$test = [
"tesT StriNg%&/()=?aj-hd_86b",
"tesTStriNgaj-hd_86b"
];
foreach ($test as $str) {
echo (!preg_match("/[^[:alnum:]\-_]/",$str)) ?
$str." is valid.\n" :
$str." is NOT valid.\n";
}
?>