How to check if a string contains only english letters, digits spaces and punctuation in PHP

1 Answer

0 votes
$str = "PHP 8.3.0 Java SE 21 .!,:';-";
  
if (preg_match('/^[a-z0-9 \p{P}]*$/i', $str)) {
    echo "true";
}
else {
    echo "false"; 
}
        
   
    
      
/*
run:
           
true
    
*/

 



answered Dec 16, 2023 by avibootz
...