本帖最后由 dahua20000 于 2011-06-23 20:55:12 编辑

解决方案 »

  1.   

    1. 正则表达式的定义要放在"//"之间。
    2. 你的办法是要找非字母或数字的字符,应该是"/[^0-9A-Za-z]/".$the_str= "123123avfghkjl_hello";
    $res=preg_match('/[^0-9A-Za-z]/',$the_str);
    if(0==$res)
    {
      echo "合法字符串";
    }
    else
    {
      echo "无效字符串";
    }
      

  2.   


    if(ereg('[^0-9A-Za-z]',$test_string)) // will be true if characters arnt 0-9, A-Z or a-z. if(preg_match('/[^0-9A-Za-z]/',$test_string)) // this is the preg_match version. the /'s are now required.