I am trying to write a regular expression in PHP so that only logins consisting of letters of the Russian and Latin alphabet, numbers, symbols _-*#!~. passed through _-*#!~. and space. Confused with Russian characters [а-я] az [а-я] , as well as with a space (used the modifier x ) Here is my regular expression:

 if (!preg_match('/^[Π°-яa-z0-9_-]+$/ix', $login)) $errors[] = 'НСдопустимыС символы Π² ΠΈΠΌΠ΅Π½ΠΈ'; 

Here, of course, not all allowed characters. Tell me please!

  • one
    And why not just list all valid characters, including whitespace? $ login = "Vova_ #! .Putin ~"; if (! preg_match ('/ ^ [\ s * \ #! \ ~ \ .a-aa-z0-9 _-] + $ / i', $ login)) {echo 'Invalid characters in the name'; } - Deonis
  • Thank you, but I also think the "u" modifier is needed - stasQa
  • It won't hurt - Deonis
  • Only for Russian characters with a register can you use this combination. [aaaaaaaa] It is necessary to specify. Since not everywhere it is supported. - manking

1 answer 1

Added answer from comments:

 $login = "Vova_#! .Putin~"; if (!preg_match('/^[\s*\#!\~\.А-Π―Π°-яЁёA-Za-z0-9_-]+$/i', $login)) { echo 'НСдопустимыС символы Π² ΠΈΠΌΠ΅Π½ΠΈ'; }