Steven Dropper
Steven Dropper

Reputation: 467

preg_match with diacritic letters also?

Basically what I need is to check whether the string contains ONLY letters a-zA-Z but also all a-zA-Z but with diacritics such as ž,č,š,ľ...also the long ones ó,ý,á,í and so on... I have no idea how to do so...

This is the only code for matching characters I know...

preg_match('/[^a-z\s-]/i',$string)

Any help much appreciated.

PS: I don't want any other characters such as $,€,%,!,.,, etc...

Upvotes: 2

Views: 557

Answers (1)

Toto
Toto

Reputation: 91430

Use unicode properties:

preg_match('/[^\pL\s-]/u', $string)

\pL stands for any letter in any language
u is a modifier for unicode character
i modifier is not needed here because \pL is for upper and lower case letters

Upvotes: 1

Related Questions