Checking Cyrillic Input in PHP

Is there a way (regular expression?) To check if a string consists of only Cyrillic alphanumeric characters?

I need to check that the input is in the Cyrillic range, plus numbers, dashes and spaces

+6
source share
1 answer

\p{Cyrillic} matches Cyrillic characters (you can use Arabic , Greek , etc. for other alphabets)

\d matches numbers

\s matches space characters

\- matches dash

 <?php header('Content-Type: text/html; charset=utf-8'); $pattern = "/^[\p{Cyrillic}\d\s\-]+$/u"; $subjects = array(12, "ab", "", '--', '__'); foreach($subjects as $subject){ $match = (bool) preg_match($pattern, $subject); if($match) echo "$subject matches the testing pattern<br />"; else echo "$subject does not match the testing pattern<br />"; } ?> 
+6
source

Source: https://habr.com/ru/post/894284/


All Articles