Morning SO. I am trying to determine if a string contains a list of specific characters.
I know that I should use preg_match for this, but my knowledge of regular expression is woeful, and I could not get information from other posts around this site. Since most of them just want to limit the lines az, AZ and 0-9. But I want some special characters to be allowed, for example ! @ Β£ ! @ Β£ , while others are not on the next line.
Characters to be matched: # $ % ^ & * ( ) + = - [ ] \ ' ; , . / { } | \ " : < > ? ~ # $ % ^ & * ( ) + = - [ ] \ ' ; , . / { } | \ " : < > ? ~
private function containsIllegalChars($string) { return preg_match([REGEX_STRING_HERE], $string); }
I originally wrote a match in Javascript, which simply looped every letter in the string, and then quoted each character in a different string until I found a match. Looking back, I canβt believe that I even tried to use such an archaic method. With the advent of json (and rewriting the application!) I will switch the match to php to return the error message via json.
I was hoping the regex guru could help convert the specified string to a regular expression string, but any feedback would be appreciated!
Stann0rz
source share