Uppercase and Lowercase Letters only and regular expression accents

Asked

Viewed 2,355 times

2

How to create a regular expression in the right way where only uppercase and lowercase letters are accepted, along with accents?

This is to validate a string by name, I created it as follows:

$String  = preg_replace("/([^a-zà-úA-ZÀ-Ú ])/", "", $String);

It works perfectly but with a however, because it comes together the characters: äåæËэээшя

There is another way to create without these characters coming together?

1 answer

0


You can include a conditional | followed by the characters between [] you want to include in the survey:

/([^a-zà-úA-ZÀ-Ú ]|[äåæËÎÏÐðÑ×÷ØÝÞß])/

If you have problems with accentuation in preg_replace, insert the flag u (Unicode):

/([^a-zà-úA-ZÀ-Ú ]|[äåæËÎÏÐðÑ×÷ØÝÞß])/u

Ideone

Regexr

Browser other questions tagged

You are not signed in. Login or sign up in order to post.