PHP: Signup > USERNAME with only Greek Characters and only one white space

标签 php regex unicode

我希望我的用户只能写出名字和姓氏之间只有一个空格的希腊字符。我该如何更改此 PHP 代码来执行此操作?

!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newusername)

最佳答案

您需要使用 the /u modifier使表达式可识别 Unicode,我更喜欢在指定此类内容时使用十六进制代码——很难区分 alpha (Α) 和 ay (A)。

According to Wikipedia ,Unicode block “希腊语和科普特语”使用从 0x370 到 0x3ff 的代码:

function checkGreek($newusername) {
    if (preg_match("/^[\x{370}-\x{3FF} ]{1,50}$/u", $newusername)) {
        echo "It's Greek to me";
    } else {
        echo "Non-Greek in there";
    }
}
checkGreek("ΑΒ ΓΔ");
checkGreek("ΑΒ ΓΔ 123");
checkGreek("AB CD");

关于PHP: Signup > USERNAME with only Greek Characters and only one white space,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42992535/

相关文章:

php - $argv 在一个类中

php - fatal error : Call to a member function prepare() on string

regex - 如何在Dart中不区分大小写的正则表达式中使用变量

python - 正则表达式 : How do I find a sub-string that is between two regular expression matches?

php - 无法从 centOS VM 远程访问 MySQL 服务器

javascript - NULL 与 MySQL、PHP、JSON 和 JavaScript

c# 正则表达式匹配太慷慨

java - 在java中打印一个平方根符号(√)

php - Zend Framework PDF 生成 unicode 问题

python - latin-1 到 ascii