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

1 Answer

0 votes
$str = "PHP 8 Java SE 21";
  
if (!preg_match('/[^A-Za-z0-9 ]/', $str)) {
    echo "true";
}
else {
    echo "false"; 
}
        
   
    
      
/*
run:
           
true
    
*/

 



answered Dec 16, 2023 by avibootz
...