search

Home  >  Q&A  >  body text

php - Why doesn't this regular expression work?

Any Chinese letters and numbers. But why can’t I pass Chinese when I try it? It has always been no. I can pass in English. Why is this?

if(preg_match("/^[a-z0-9\xa1-\xff]{1,8}$/",$username)){
 echo "yes";
}else{
 echo "no"
}
为情所困为情所困2774 days ago409

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 13:17:42

    preg_match() returns the number of matches for pattern. Its value will be 0 (no match) or 1 because preg_match() will stop searching after the first match. So aaa returning 'no' is normal.

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:17:42

    /^[a-z0-9\u4e00-\u9fa5]{1,8}$/

    http://m.111cn.net/art-42203.htm

    reply
    0
  • Cancelreply