good people) Tell me, please, how can you determine the presence of extra characters in the string? The string should consist of only 1) Russian lowercase and uppercase letters and spaces, or 2) words from Russian letters with a capital letter (or two words with capital letters with a hyphen between them)

Those. A string is either a full name together, or a surname, name and patronymic separately.

I read about preg_match, but I really can't compose a template. And in general I am stupid in a terrible way. Or, maybe, you can somehow compare the characters from the array ... Help, please.

    2 answers 2

    /^[А-Я][а-я]*([-][А-Я][а-я]*)?\s[А-Я][а-я]*\s[А-Я][а-я]*$/ 
    • And the locale does not need to install any? Thanks for the answer. There is no way to check. In the evening I will unsubscribe. - Ruslan
    • one
      @ Ruslan what to install locally? - madfan41k
    • Not locally) I read somewhere that I need to define a locale in the code. Command setlocale. It is possible, of course, that I didn’t concentrate on that - Ruslan
    • nothing comes out. Skis do not go skiing, toli, I'm a fool. $ slovo = 'abv14., g'; if (preg_match ('/ ^ [AZ) [AZ] * ([-] [AZ] [az] *)? \ s [AZ] [az] * \ s [AZ] [AZ] * $ / ', $ slovo)) {echo "not that ((";} else {echo "OKKKK !!!";}} For any word displays "OKKKK !!!" - Ruslan
    • Locale, in fact, does not need to be installed - Ruslan

    In general, the decision is ...

     if (preg_match('/^[а-яё ]++$/ui', $name)) { echo 'Правильно: '.$name; }else{ echo 'НЕПРАВИЛЬНО: '.$name; } 

    I haven't figured out exactly what's what, but it works. Only does not determine whether the uppercase letters of words