So I want to validate a string based on whether or not it contains only grammatical characters as well as numbers and letters.(basically A-Z, a-z, 0-9, plus periods(.), commas(,) colons(:), semicolons(;), hyphens(-), single quotes(‘), double quotes(“) and parentheses(). I am getting a PHP error that says “Compilation failed: range out of order in character clas”. What regex code should I be using?
This is the one I’m currently using:
^[a-zA-Z0-9_:;-()'\" ]*^
You need to escape
-which would then become this^[a-zA-Z0-9_:;\-()'\" ]*.-has a special meaning inside character set so it needs to be escaped.^in the end is also not necessary. The regex can also simplified using\wlike this\wmatches letters, digits, and underscores.