polak polkovski polak polkovski - 3 years ago 277
PHP Question

Minimum one upper character in string

How can I check if string contains a minimum one uppercase character in encoding UTF-8? I checked this with


preg_match('/[A-Z]/', $var)

but this code doesn't work with all characters for example

How can I fix it?

Answer Source

A-Z is looking between the ascii ranges. The characters you are displaying are outside of that range. Use \p{Lu} and use the unicode modifier u.

preg_match('/\p{Lu}/u', $var)

Demo: https://regex101.com/r/WZaOCD/1/

For more unicode options please see http://php.net/manual/en/regexp.reference.unicode.php.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download