douzhi1972 2016-08-07 17:46
浏览 81

检查php字符串是否是包含西里尔字符的字母数字?

I have found a lot of different patterns on the net (tested them all), i have also added encoding to the page, but nothing seams to work. This is my code:

<?php header('Content-Type: text/html; charset=utf-8'); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
<?php



$teststring="cc12cž";


$pattern  = "/^[p{L}\p{M}\a-zA-Z*0-9\s\-]+$/u";
if(preg_match($pattern, $teststring))
    {echo"IT IS ALFANUMERIC";}
else
    {echo"ERROR";}


?>

</body></html>

This is what i tried

//$pattern  = "/^[\p{L}\p{M}\a-zA-Z*0-9\s\-]+$/u"; 
//$pattern  = "/^[p{L}\p{M}\a-zA-Z*0-9\s\-]+$/u"
//$pattern  ='/^[a-zA-Z\p{Cyrillic}\d\s\-]+$/u'
//$pattern  ="/(*UTF8)^[[:alnum:]]+$/"
//$pattern  ="/^[a-zA-Z\p{Cyrillic}\p{Cyrillic}]+$/u"
  • 写回答

1条回答 默认 最新

  • dtzh131555 2016-08-08 06:33
    关注

    I did a test using ZF Zend_Validate_Alnum and your string seems to validate correctly.

    $validator = new Zend_Validate_Alnum();
    if ($validator->isValid('cc12cž')) {
        // value contains only allowed chars
        echo "IT IS ALFANUMERIC";
    } else {
        echo "ERROR";
    } 
    

    From what I see their validation technique is quite simple and it does not involve regexp:

    if (!is_string($value) && !is_int($value) && !is_float($value)) {
        $this->_error(self::INVALID);
        return false;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭