I want to use a regex to limit valid characters. I.e:
a - z A - Z 0 - 9 _ - ~ ! @
and this is my regular function:
function validChr($str) { return preg_match('/^[A-Za-z0-9_~\ -!@ #\$%\^&*\(\)]+$/',$str); }
I really tried this and the result is how I want, but I was still not sure. Is my regex correct? Or are there other forms of regex? Please help as I am still new to this regex. Thanks.
source share