Page 1 of 1

preg_match for hebrew characters?

Posted: Sun Nov 22, 2009 5:02 am
by metalball
hey all,

i'm trying to make this function:

Code: Select all

    function alpha_space($str)
    {
        return ( ! preg_match("/^([-a-z0-9_\ -])+$/i", $str)) ? FALSE : TRUE;
    }
 
check also hebrew characters, but i fail every time...

i've tried:

Code: Select all

    function alpha_space($str)
    {
        return ( ! preg_match("/^([-a-z\x{5D0}-\x{5EA}0-9_\ -])+$/i", $str)) ? FALSE : TRUE;
    }
 
but its no good...
also

Code: Select all

    function alpha_space($str)
    {
        return ( ! preg_match("/^([-a-z?-?0-9_\ -])+$/i", $str)) ? FALSE : TRUE;
    }
 
same thing...

how can it be done?

thanx...

Re: preg_match for hebrew characters?

Posted: Sun Nov 22, 2009 5:54 am
by Apollo
PHP's preg_* functions are based on PCRE, you need to add the u (unicode) modifer at the end (so "$/iu") for this to work.

Re: preg_match for hebrew characters?

Posted: Sun Nov 22, 2009 6:52 am
by metalball
:drunk:
thanx ALOT!
worked like a charm...

working code if anyone interested:

Code: Select all

 
    function alpha_space($str)
    {
        return ( ! preg_match("/^([-a-z\x{5D0}-\x{5EA}0-9_\ -])+$/iu", $str)) ? FALSE : TRUE;
    }