Reputation: 7
I would like to in form I can enter only the letters of the alphabet, numbers, and square brackets, except for special characters. Whether the brackets to include special characters? I have such:
if (preg_match("/[^a-zA-Z0-9]+/", $characters))
{
echo "Write only letters of alphabet and numbers!";
}
It detects letters and numbers correctly, does not pass the special characters but how to do that I can also enter the square brackets?
Upvotes: 0
Views: 5305
Reputation: 535
As adeneo says,
if (preg_match('/[^a-zA-Z0-9\[\]]+/', $characters))
{
echo "Letters, numbers and square brackets only!";
}
Upvotes: 2