preg_match allowing a-z AND å ä ö ü

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

    preg_match allowing a-z AND å ä ö ü

    I've been searching the net and Google news groups for a preg_match
    expression that will return true on strings containing (uppercase and
    lowercase) characters of A-Z, 0-9 and for instance Swedish characters Å Ä Ö.
    It should return false on strings containing stuff like -#¤%\"[]()=?&/.

    The thing is, I don't want to specifically allow Å Ä Ö, I want a more
    general rule in case other characters like ü or ø turn up. Is this possible
    to do?

    I've tried
    preg_match("/^\w+$/", $string)
    and
    preg_match("/^[[:alpha:]]+$/", $string)

    but both returns false on everything except a-z A-Z.

    I'm going to use it to test a receiver's name ($to_name) before putting it
    in an e-mail header like "$to_name <$to_email>"; The names are entered in a
    text field by my users and I want to test the name so it won't mess up the
    e-mail header causing the e-mail to fail.

    Any help would be greatly appreciated. Thank you.

    Daniel


  • Pedro Graca

    #2
    Re: preg_match allowing a-z AND å ä ö ü

    Daniel wrote:[color=blue]
    > I've been searching the net and Google news groups for a preg_match
    > expression that will return true on strings containing (uppercase and
    > lowercase) characters of A-Z, 0-9 and for instance Swedish characters Å Ä Ö.
    > It should return false on strings containing stuff like -#¤%\"[]()=?&/.
    >
    > The thing is, I don't want to specifically allow Å Ä Ö, I want a more
    > general rule in case other characters like ü or ø turn up. Is this possible
    > to do?
    >
    > I've tried
    > preg_match("/^\w+$/", $string)
    > and
    > preg_match("/^[[:alpha:]]+$/", $string)
    >
    > but both returns false on everything except a-z A-Z.
    >
    > I'm going to use it to test a receiver's name ($to_name) before putting it
    > in an e-mail header like "$to_name <$to_email>"; The names are entered in a
    > text field by my users and I want to test the name so it won't mess up the
    > e-mail header causing the e-mail to fail.
    >
    > Any help would be greatly appreciated. Thank you.
    >
    > Daniel[/color]


    <quote source="RFC2822 ">
    Note: This standard specifies that messages are made up of characters
    in the US-ASCII range of 1 through 127. There are other documents,
    specifically the MIME document series [RFC2045, RFC2046, RFC2047,
    RFC2048, RFC2049], that extend this standard to allow for values
    outside of that range. Discussion of those mechanisms is not within
    the scope of this standard.
    </quote>

    So, according to this standard those characters you want to include in
    the header part of your email are invalid :)


    Anyway, I think it should work if you

    <?php setlocale(LC_AL L, 'se_SE'); ?>
    I have no idea about the correct locale string ('se_SE') for you.


    --
    ..sig

    Comment

    Working...