格式必须是:如(1~20M)!
数字间用“~”隔开……

解决方案 »

  1.   


    re = /^\d+~\d+M$/re = /^\(\d+~\d+M\)$/
      

  2.   


    var str="(111~20M)";
         var rex=/^\(\d+~\w+\)/g;
         alert(rex.test(str))
      

  3.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="JavaScript" type="text/javascript">   window.onload=function(){
         var str="(20~120M)";
         var rex=/^\((\d+)~(\d+)M\)/;
         if(rex.test(str)&&parseInt(RegExp.$2)>parseInt(RegExp.$1))
              alert("匹配")
       }
    </script>
    </head>
    <body>
    </body>
    </html>
      

  4.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="JavaScript" type="text/javascript">   window.onload=function(){
           var s1="(1~10M)";
           var s2=("10~5M");
           var s3="(100~1000我)";
         alert(isYourNeed(s1));
         alert(isYourNeed(s2));
         alert(isYourNeed(s3));
       }
       function isYourNeed(str){
            var rex=/^\((\d+)~(\d+)[\w|\u4E00-\u9FA5]\)/;
           if(rex.test(str)&&parseInt(RegExp.$2)>parseInt(RegExp.$1))
               return true;
           else return false;
       }</script>
    </head>
    <body>
    </body>
    </html>