W3docs

Allow only [a-z][A-Z][0-9] in string using PHP

You can use the preg_replace function in PHP to remove any characters that do not match the specified pattern.

You can use the preg_replace function in PHP to remove any characters that do not match the specified pattern. To allow only lowercase letters, uppercase letters, and digits in a string, you can use the following code:

Example of allowing only [a-z][A-Z][0-9] in string using PHP

php— editable, runs on the server
Info

Watch a video course: Learn object oriented PHP

This will remove all characters that are not lowercase letters, uppercase letters, or digits from the $string variable.