I'm trying to write a function that checks for special characters in a string, and regular expressions are confusing me.
I need a function that returns false if it comes accross anything except alphanumeric characters, and one that returns false for everything except alphanumeric and the characters "()-_." (minus quotes)
Thanks for your help!
// This would return 1 if $what contains only a-z A-Z and 0-9 function check1($what) { return ereg("[a-zA-Z0-9]*$", $what); }
To add the extra characters to the "allow" list, replace the above ereg with;
ereg("[a-zA-Z0-9().-_]*$", $what);
Try this pattern: preg_match("/[\W_]+/",$sample)