var filter=/^\s*[A-Za-z0-9\u4e00-\u9fa5_-]{3,12}\s*$/;
if (!filter.test(user_name)){document.getElementById("user_nameinfo").innerHTML="<font color=red>只能有:中文、字母、数字、下划线、中划线</font>";return false;}这是javascript正则,我想把他改成PHP的,不知道需要改那里呢?

解决方案 »

  1.   

    if(preg_match('/^\s*[A-Za-z0-9\x4e00-\x9fa5_-]{3,12}\s*$/',$str))
      echo "只能有:中文、字母、数字、下划线、中划线";没有测试,大概就是这样了,建议你去看一下PHP手册
      

  2.   

    if(preg_match('/^\s*[A-Za-z0-9\x4e00-\x9fa5_-]{3,12}\s*$/',$str))
      echo "只能有:中文、字母、数字、下划线、中划线";没有测试,大概就是这样了,建议你去看一下PHP手册
      

  3.   

    基本上不需要改的 PHP 对应的函数。preg_match        //匹配一次preg_match_all    //匹配所以
      

  4.   

    preg_match('/^\s*[A-Za-z0-9\x{4e00}-\x{9fa5}_-]{3,12}\s*$/iu',$str)