PHP: Regex alphanumeric and some special characters only
php, regex
Solution
It works as it should.
You should only add \ before * to escape it.
Check it out here: Regular expression test
Problem
I want to use a regex to limit the characters allowed. That is: ``` a - z /* a to z */ A - Z /* A to Z */ 0 - 9 /* 0 to 9 */ _ - /* underscore & dash */ ~ ! @ # $% ^ & * () /* allowed special characters */ ``` and this is my regex function: ``` function validChr($str) { return preg_match('/^[A-Za-z0-9_~\-!@#\$%\^&*\(\)]+$/',$str); } ``` I've actually tried it and the result as I want, but I still was not sure. Is my regex is correct? Or are there other forms regex? Please help as I am still new about this regex. Thank you.