preg_match("#^[aA-zZ0-9\-_]+$#",$fullName 

the question is how to add Russian and Ukrainian characters here, because it turns out like: you can enter English letters, space, underscore, hyphen, and how to add other characters there.

And explain how you do it, a little is not clear.

And there is one question.

There is also a mail () function, so when I send a letter to Google Mail, it supposedly comes from, say, "X@gmail.com", and how to make the sender always specify the same email "Y@gmail.com".

Because google reports the following: "Perhaps this email was not sent from X@gmail.com. More ... Report Phishing."

  • put the question about the letters in a separate, one post = one question - Bookin
  • And why not go on the principle of KISS? If you only allow letters and numbers, use a simple template: [\w\d]+ . What is the alphabet it will understand. - PinkTux
  • @PinkTux, \d is part of \w . - Qwertiy

3 answers 3

how to add Russian and Ukrainian characters here, because it turns out like: you can enter English letters, space, underscore, hyphen, and how to add other characters there.

Let's start from KISS (make it easier, that’s). Trimmed the input (removed leading / trailing spaces, do not forget about it), and then:

 /^[\w]+$/ 

So fit? Well, do not forget about the u modifier.

However, with this approach it is not entirely clear why you need this check at all. Or do you need something else: cut off something that is not part of a particular alphabet?

    The square brackets of your expression list the characters you need to find, now the rule will find all the small and large letters of the English alphabet, numbers from 0 to 9, a dash and an underscore. By analogy, you can add Russian letters - аА-яЯ , they will also be for the Ukrainian alphabet, plus you need to add letters that are specific - ЁёІіЇїЄєҐґ . In the end, you get something like:

     preg_match("#^[aA-zZаА-яЯЁёІіЇїЄєҐґ0-9\-_]+$#",$fullName); 

    As Pink Tux wrote correctly, you can replace all enumerations of characters, search for the metacharacter \w it searches for an alphabetic or numeric character or underscore, and add the u flag. The result will be:

     preg_match("#^[\w\-]+$#u",$fullName); 
    • Thanks, and what should be the encoding in the php file? - user215557
    • must be utf8 without BOM - splash58

    Add u modifier: preg_match ("# ^ [aaaaa-z0-9 -_] {3,20} $ # iu", $ fullName) I completely forgot, you need to add Russian characters

    • unfortunately does not work - user215557
    • Give examples of names that do not work. - PinkTux
    • @PinkTux, I think, Ukrainian with letters like ҐґЄєЇї . Perhaps, some other shoals due to the fact that the alphabet does not go in a row. - Qwertiy