RegEx "/[^A-z]/"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Flos

    RegEx "/[^A-z]/"

    Hello!

    I want to make a validation for a string which can be only letters AND
    space. for example "apple house", but not "apple3 house"

    i have found

    if (preg_match ("/[^A-z]/", $string)) return false
    esle return true

    this does not accept a space. i tried \s, \S. and [:space:] but it
    didn't work.

    I tried several tutorials, but my problem is not mentioned there. And to
    say the true RegEx seem pretty difficult to me.

    I apreciate any help,

    Flos

    sorry for spelling mistakes
  • Andy Hassall

    #2
    Re: RegEx "/[^A-z]/"

    On Fri, 14 May 2004 16:45:31 +0200, Flos <florian_peer@h otmail.com> wrote:
    [color=blue]
    >I want to make a validation for a string which can be only letters AND
    >space. for example "apple house", but not "apple3 house"
    >
    >i have found
    >
    >if (preg_match ("/[^A-z]/", $string)) return false
    >esle return true
    >
    >this does not accept a space.[/color]

    It shouldn't do, you haven't included space in the character class. And you've
    got a lot more than you probably want.

    A-z is:

    ABCDEFGHIJKLMNO PQRSTUVWXYZ[\]^_`abcdefghijkl mnopqrstuvwxyz
    [color=blue]
    >i tried \s, \S. and [:space:] but it didn't work.[/color]

    You said you wanted a space, not all whitespace.
    What makes you think it "didn't work"? Prove it with an example.
    [color=blue]
    >I tried several tutorials, but my problem is not mentioned there. And to
    >say the true RegEx seem pretty difficult to me.[/color]

    /[^A-z]/ means match any string that contains a character other than the load
    I posted above.

    Sounds like you want:

    /[^A-Za-z ]/

    Or:

    /[^a-z ]/i

    --
    Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
    http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

    Comment

    • Flos

      #3
      Re: RegEx &quot;/[^A-z]/&quot;

      In article <7mcaa0ln8kir6i qanf0uauv3vknso 72mgu@4ax.com>,
      andy@andyh.co.u k says...[color=blue]
      > /[^A-Za-z ]/
      >[/color]

      thats it, thank you very much

      :)

      Flos

      Comment

      • Jeff Rodriguez

        #4
        Re: RegEx &quot;/[^A-z]/&quot;

        Flos wrote:
        [color=blue]
        > Hello!
        >
        > I want to make a validation for a string which can be only letters AND
        > space. for example "apple house", but not "apple3 house"
        >
        > i have found
        >
        > if (preg_match ("/[^A-z]/", $string)) return false
        > esle return true
        >
        > this does not accept a space. i tried \s, \S. and [:space:] but it
        > didn't work.
        >
        > I tried several tutorials, but my problem is not mentioned there. And to
        > say the true RegEx seem pretty difficult to me.
        >
        > I apreciate any help,
        >
        > Flos
        >
        > sorry for spelling mistakes[/color]


        Change your " to ' and use \s

        Jeff

        Comment

        Working...