<html>
 <head>
  <title> New Document </title>

 <script language="javascript">
 function cc(){
        var s="12222北京";
        var s2="12222北京";
        var s3=" 1 2 2 2 2 北京";
        //取数字
        s=s.replace(/[^\d]*/ig,"");
        alert(s);
        //取中文
        s2=s2.replace(/[\d]*/ig,"");
        alert(s2);
        //去掉所以空格
        s3=s3.replace(/\s/ig,"");
        alert(s3);
        }
    </script>

 </head>

 <body>
  <input type="button" value="提交" οnclick="cc();">
 </body>
</html>