preg_match string regex code example Example: preg_match if(!preg_match('/^\[a-zA-Z]+$/',$input)) { // String contains not allowed characters ... }