Regular Expression - no accents

Discussion in 'Programming' started by AstarothSolutions, Mar 15, 2008.

  1. #1
    For a personal project I am trying to write a wee page which includes needing to validate text against a regular expression....

    I want to only allow a-z and 0-9 but exclude â etc. At the moment I have:
    ^[a-zA-Z0-9]\w{1,30}$
    Code (Regular Expression):
    This works for most things but not accented letters.... any ideas what I need to add to exclude these?
     
    AstarothSolutions, Mar 15, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You don't want it to allow accented letters? Why even do the \w part then? Try just running it against "^[a-zA-Z0-9]{1,30}$"
     
    zerxer, Mar 15, 2008 IP
  3. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Because whilst I conn myself into thinking I can do programming things like regex I know I dont know much about so would normally let my developers do but weekend + personal project means that I am reliant on websites :)
     
    AstarothSolutions, Mar 15, 2008 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    This pattern will work when multibyte support is enabled.
    #^[a-z0-9]{1,30}$#i
    Code (markup):
    When you run phpinfo(), do you have an mbstring section ?
    If you do, what's listed for the options in that section ?
    Does it mention anything about Multibyte regex (oniguruma) version ?
     
    joebert, Mar 15, 2008 IP
  5. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Have never run phpinfo() in my life, will be a Page.Validate() command as it is a .Net application
     
    AstarothSolutions, Mar 17, 2008 IP
  6. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #6
    Sorry about that, thought I was still in the PHP section.

    The "Set the correct character set" section in this MSDN article looks promising.
     
    joebert, Mar 17, 2008 IP
  7. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #7
    No problem, made the same mistake myself the other day by posting a .Net solution in the PHP section.... was interesting to see the 6 lines or so in .Net took 30+ in PHP to do the same thing though.
     
    AstarothSolutions, Mar 17, 2008 IP