Regex for Cyrillic characters

As we have a lot of russian members here, maybe someone can help: I couldn’t find much information wether it’s possible to check for cyrillic characters (А-Я) with a regular exp​ression in PHP. Any hints are highly appreciated!

Thanks!

Should be А-Яа-я

Thanks. Did you verify this? I thought there are some problems with UTF-8 + regex. A comment in the PHP manual says, that PCRE functions aren’t UTF-8 safe. It states that you can only use mb_ereg* functions and need to alter this:


<?php

  mb_internal_encoding('UTF-8');

  mb_regex_encoding('UTF-8');

  setlocale(LC_ALL, 'fr-fr');

I’m talking about preg_ with unicode modifier, not ereg.

Ah, thanks a lot. Didn’t know that one.

Maybe this will be useful as well…

Regards.

I had the same issue, so I have searched too.

One option: "/^[А-Я]+$/u".

A successful cyrillic, latin alphanumeric validation for Yii2…


public function rules()

{

    return [

['name', 'match', 'pattern' =&gt; '/^[А-Яа-яA-Za-z0-9\s_-]+$/u', 'message' =&gt; 'Your username can only contain alphanumeric characters, underscores and dashes.'],

    ];

}

If you need russian characters… - ‘/[А-Яа-яЁё]/u’ - This may help.