Page 1 of 1

the regex does not allow comma for me

Posted: Mon May 15, 2006 4:14 am
by raghavan20
I am trying to allow a few characters in a pattern match and I want to allow comma as well. I am trying to escape comma since it is a special character but the regex engine does not seem to accept.

Code: Select all

preg_match("#[^a-zA-Z0-9\s\.-\,]#", $_POST['city'])


error: Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 17

Posted: Mon May 15, 2006 7:30 am
by feyd
A comma isn't a metacharacter last I checked. The complaint is coming from your usage of the minus sign, which is a metacharacter in a character class. If you want to allow a minus to appear in the match, escape it. Otherwise, you'll need to swap the comma and period to make them in ordinal ascension.