#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    64
    Rep Power
    10

    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?

    ^([A-z 0-9]*)$

    used in a php context

    Code:
    !ereg("^([A-z 0-9]*)$", $string)
    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

    ^

    Just so i know its not my php environment screwed up, i tried it here...
    http://www.fileformat.info/tool/regex.htm

    using ^([A-z 0-9]*)$

    and the following strings

    Code:
    dfvfd45t54
    srfdfcdf
    ^fdvdf
    and that was doing the same. Am i missing out on something here?

    Thanks in advance for any replies
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    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.:
    Code:
    ^([A-Za-z 0-9]*)$
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    64
    Rep Power
    10
    ahh ok, I used that method as it was recommended on a few websites. I now know not to.

    Thanks very much

IMN logo majestic logo threadwatch logo seochat tools logo