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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    260
    Thanks
    183
    Thanked 0 Times in 0 Posts

    How to allow multi langauges name with ereg or preg?

    I want to make the user names could be by Arabic and English letters, and the problem is how to check the name characters with ereg function and allow the letters of both languages?
    this is my function :

    if(ereg("^[أ-يA-Za-z1-9 '_-]{3,50}$",$username))
    {

    }

    and this function doesn't allow the Arabic characters that start from أ to ي

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Haven't done this before, but manual says, you could use something like
    PHP Code:
    "^[\x{0623}-\x{064A}A-Za-z1-9 '_-]{3,50}$/u" 
    PS: All ereg related functions are deprecated, use their preg equivalents
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Mido™ (08-27-2010)

  • #3
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    260
    Thanks
    183
    Thanked 0 Times in 0 Posts
    I didn't use preg before but from the manual I found there aren't big differences except the slash / , in any way the problem happened with ereg and preg, and function you gave me didn't fix.
    also when I use the function htmlentities($name,ENT_QUOTES,'UTF-8') the name become nothing and empty, and without using it the ereg function give an error say :
    Warning: ereg() [function.ereg]: REG_ERANGE in

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    in any way the problem happened with ereg and preg, and function you gave me didn't fix.
    I haven't given any function. The following code gives me the output Okay
    PHP Code:
    <?php
    $str
    ='Some-العربية';
    if(
    preg_match("/^[\x{0623}-\x{064A}A-Za-z1-9 '_-]{3,50}$/u",$str ))
        echo 
    'Okay';
    else
        echo 
    'Not Okay';

    ?>
    where as
    PHP Code:
    <?php
    $str
    ='Some-پانی';
    if(
    preg_match("/^[\x{0623}-\x{064A}A-Za-z1-9 '_-]{3,50}$/u",$str ))
        echo 
    'Okay';
    else
        echo 
    'Not Okay';

    ?>
    gives me Not Okay
    Last edited by abduraooft; 08-27-2010 at 01:01 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Mido™ (08-27-2010)

  • #5
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    260
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Thanks for your help, I was mean that way didn't fix, I used this preg function

    preg_match("/^[a-z A-Z0-9أ-ي]+$/i", $username)

    and it's work but with 2 problems:
    - a few arabic letters aren't accepted like " ع" "غ" "ك"
    - after inserting the name in the DB I couldn't search or select it! when I select it I get nothing although when I inserted it again the DB didn't allowed as it a double entry.

    and about the functions you wrote in the last post, they worked as you said and I don't know how this although they are the same!
    Last edited by Mido™; 08-27-2010 at 02:03 PM.


  •  

    Posting Permissions

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