...

View Full Version : How to allow multi langauges name with ereg or preg?



Mido™
08-27-2010, 01:39 AM
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 ي

abduraooft
08-27-2010, 07:11 AM
Haven't done this before, but manual (http://php.net/manual/en/function.preg-match.php) says, you could use something like
"^[\x{0623}-\x{064A}A-Za-z1-9 '_-]{3,50}$/u"

PS: All ereg related functions are deprecated, use their preg equivalents

Mido™
08-27-2010, 12:45 PM
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

abduraooft
08-27-2010, 12:58 PM
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
$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
$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

Mido™
08-27-2010, 01:47 PM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum