November 4th, 2008, 10:58 AM
Caret symbol accepted
Please tell me if I'm wrong, but shouldn't the following regex query identify only the letters a-z A-Z 0-9 and space?
used in a php context
I want it to pick out when characters other than a-z, 0-9 and space's are used. However it is allowing the caret symbol through
!ereg("^([A-z 0-9]*)$", $string)
Just so i know its not my php environment screwed up, i tried it here...
using ^([A-z 0-9]*)$
and the following strings
and that was doing the same. Am i missing out on something here?
Thanks in advance for any replies
November 4th, 2008, 05:45 PM
Note you've used a capital A and a lowercase z.
That means accept any character from ASCII code 66 (A) to ASCII code 122 (z). Since the caret character is code 94, it's one of the ones included.
If you want to cover both upper- and lowercase letters, you have to separate them, i.e.:
November 5th, 2008, 08:02 AM
ahh ok, I used that method as it was recommended on a few websites. I now know not to.
Thanks very much