Problem in restricting "@" in username of signup form.
I am creating a website where i want to know how to restrict "@" in php.
I tried preg replace
preg_replace('/@/', '@', $username);
but it is not working. What is the appropriate ‘preg_replace’ value to restrict ‘@’ in php.
2
Answers
You can use str_replace preg_replace to remove all ocurrencies of the @ symbol
All of these are essentially equivalent.
The last one can take a list of restricted characters within the square brackets
If you want to just check for an @ symbol, I would use
strpos
insteadTo check the presence of a substring, you can use str_contains