Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Smile How Alow European special characters in a string

    I need to check some name fields in a form to see that it only contain alpha charecters that shud be simple. However the European languages contains more letteres than a-z

    It must allow special European characters like æøåöäçêé and so on (but not signs like $€"#/=+? and so on)


    i cud try making a list of all the charecters allowed, lucky this form is mostly for westen europa / skandinavian, but if i shud make a form for the whole europa (not to say worldwide) the list woud be VERY long.
    The European languages is divided into 13 diferent ISO set and some of the sets have letters where others have signs

    What woud be the best way to do this ?
    Last edited by Jesper Møller; 02-16-2010 at 09:56 PM.
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Pattern matching is probably the easiest way to do this.
    I'd expect that locale matching using just \w would provide the accentuated characters. If not, you can try to use the unicode patterns with \pL+. I believe you need to use the u modifier when you're dealing with multibyte charsets though.
    Aside from that, you can use the mbstring library to see if it has anything useful.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks for you input
    But i must admit i simply dont understand annything of that code
    (Yes im new to php)

    du you meen somthing like preg_match("/\pL+/u", $name) ??
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by Jesper Møller View Post
    Thanks for you input
    But i must admit i simply dont understand annything of that code
    (Yes im new to php)

    du you meen somthing like preg_match("/\pL+/u", $name) ??
    o.O
    Thats exactly what I meant yes. Did it work?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    o.O
    Thats exactly what I meant yes. Did it work?
    Not shue if it works yet ... trying it out
    Must say thodse expresion is giving me a hard time...
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #6
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Well ... its ALMOST working

    Try this

    PHP Code:
    $test1 "abcdefghijklmnopqrstuvwxyzæøå 0123456789";
    echo 
    $test1."<br><br>";
    echo  
    preg_replace('/\pL[0-9]+/u','',$test1);
    echo 
    "<br><br>";
    $test2 "abcdefghijklmnopqrstuvwxyzæøå0123456789";
    echo 
    $test2."<br><br>";
    echo  
    preg_replace('/\pL[0-9]+/u','',$test2); 
    test2 will removed the å
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #7
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Also problem if ther is a / in the string

    PHP Code:
    $test "abcdefghijklmnopqrstuvwxyzæøå0123456789.-&#012æøå";
    echo  
    preg_replace('/\pL+/u','',$test);
    echo 
    "<br><br>";
    $test2 "abcdefghijklmnopqrstuvwxyzæøå0123456789.-&/#012æøå";
    echo  
    preg_replace('/\pL+/u','',$test2);
    echo 
    "<br><br>"
    that gives:
    0123456789.-
    and
    0123456789.-&/#012
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #8
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Think ill have to play with this a lot to get it to work as i want :-P
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Hah, yep. I can't test this ATM since I'm at work, and I'm busy getting things ready to go to move to a new place, but I'll try to test this out when I get home.

    Its looking pretty good so far though, I would expect that it shouldn't remove the &#012, but it clearly does (I wouldn't consider 012 to be a character that you'd want to use).
    Try this for you're pattern: /(\pLu|\pLT|\pLl)+/u. That will skip 'modified' and 'other' letters, but I'm afraid I have no idea what either are defined as
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #10
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks Fou-Lu

    Im simply trying/testing diffrent combination and seeing what is hapning and that way trying to learn the ways of expresion
    Ill try you sugestion...

    My goal is to allow only letters and space . - & sign in the names :-)
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #11
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Funny ... /(\pLu|\pLT|\pLl)+/u only removes kl frome the string :-)
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #12
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Think i got it now

    if (strlen(preg_replace('/[\.\-\s\&]|\pL+/u','',$test)) >0) {
    echo "ERROR";
    }

    This shud allow for names like:
    Møller
    Mr. Jensen
    Hans-Christian
    Jönson
    Glud&Marstand

    Proberly cud ben don smarter, and ill stil have to do some more testing
    (And have to figure out what \p and L actualy do)

    Thanks for the help
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    \p indicates unicode sets in use, L indicates letter (breakdowns are things like Letter Upper, Letter Lower, Letter Title, Letter Other and Letter Modified).

    Glad you got it sorted out.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    Jesper Møller (02-16-2010)

  • #14
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks

    Playd with them a little .. got that P vs p thing gave me letters vs not letters
    But thought that the u was for unicode (its surly looks funny if i remove it)

    pLT and pLl i cud not get to work
    pLt removed st frome the string
    PLl removed kl frome the string
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •