Yii Framework Forum: Regex for Cyrillic characters - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Regex for Cyrillic characters Rate Topic: -----

#1 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,017
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 23 July 2009 - 02:56 AM

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!
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,193
  • Joined: 17-January 09
  • Location:Russia

Posted 23 July 2009 - 08:17 AM

View PostMike, on 23 July 2009 - 02:56 AM, said:

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 А-Яа-я
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#3 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,017
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 24 July 2009 - 03:14 AM

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');

0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,193
  • Joined: 17-January 09
  • Location:Russia

Posted 24 July 2009 - 03:26 AM

I'm talking about preg_ with unicode modifier, not ereg.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#5 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,017
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 24 July 2009 - 03:30 AM

View Postsamdark, on 24 July 2009 - 03:26 AM, said:

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


Ah, thanks a lot. Didn't know that one.
0

#6 User is offline   Nemoden 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-March 09
  • Location:Vancouver, Canada

Posted 16 August 2009 - 04:47 AM

Maybe this will be useful as well...

Regards.
No brain - no pain.
My twitter :D
0

#7 User is offline   koredalin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 23-September 17

Posted 29 November 2017 - 05:49 PM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users