Jump to content

Recommended Posts

Hi,

 

I need to validate international alphabetic characters.

 

I need to get TRUE with characters like "ç", "é" and others, but is not working. How can I validate characters with accents? I have this:

 

function alpha($str)
{
return ( ! preg_match("/^([*A-Za-zá-úÁ=Ú.\s*])+$/i", $str)) ? FALSE : TRUE;
}

 

Someone can give me a clue on how to validate characters with accents?

 

Best Regards,

\w is not to be relied on for this kind of problem as precisely what it matches varies between different locales in use.  I'm sure there have been threads discussing exactly that topic which might be worth a search.

 

By "international alphabetic characters" do you mean absolutely any letter character at all? If so then \pL (make sure to use the u modifier) will likely be sufficient.  If you only want accented latin characters, then \pL would be overkill. So it depends what precisely you are wanting to match.

Hi,

 

I'm  trying to get this working, but without success.

 

I'm trying to validade "André" as TRUE, but gives me FALSE

 

Here is the code:

 

function alpha_international($str){
	return ( ! preg_match("/^[\pL]+$/", $str)) ? FALSE : TRUE;
} 

 

Someone can give me a clue?

 

Best Regards,

 

/[\pL]+/ seems to be working, but really I've no experience with unicode regex to say how good it is.

 

BTW:

return ( ! preg_match($pattern, $str)) ? FALSE : TRUE;

 

and

return (bool)preg_match($pattern, $str);

 

do same thing

 

 

Here's how I would do it, compare the function with yours to see the differences. :shy:

 

function alpha_international($subject) {
    return (bool) preg_match('/^\pL+$/Du', $subject);
}

 

Thanks for the reply.

 

"André" is now OK. I need also to recognize Spaces as OK, to "André Lopes" be recognized as OK.

 

Sorry for my questions. I know I need to study Regex...

 

Best Regards,

Spaces plural or just one, or?.. Sorry if this sounds like 20 questions but you need to be precise.

 

This will match multiple words (at least one word; consisting only of 'letters') separated by a single space:

 

/^\pL+(?: \pL+)*$/Du

Spaces plural or just one, or?.. Sorry if this sounds like 20 questions but you need to be precise.

 

This will match multiple words (at least one word; consisting only of 'letters') separated by a single space:

 

/^\pL+(?: \pL+)*$/Du

 

Hi salathe,

 

No more needed. It does everything I need.

 

Thanks for your help and patience.

 

Best Regards,

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.