I want to make user input valid , therefor i’m using regual expression.
I’d like the user to insert only alphanumeric content and some specific characters as – ,!$^& etc.
So far the code I’ve got is :
$validText = preg_replace('@[^A-Za-z0-9\w\ ]@', '',$text);
But it only care for alphanumeric and spaces , but how do I define the regual expression to refer to characters as .’!@# and etc ? Where do I define it ?
By the way, could you please refer me to a good regular expression?
Any suggesti
Simply add them to your group.
Note:
preg_match()may be better suited in this case. Currently you’re allowing invalid characters then removing them. Makes for a poor user experience.