看板 Ajax 關於我們 聯絡資訊
※ 引述《PTTFHK ()》之銘言: : function doCheck(num,int,dec){ : var pattern = /^\d{1,int}$|\d{1,int}\.\d{1,dec}$/; : if(num.match(pattern)==null){ : alert("不符合規定!"); : }else{ : alert("通過檢核!"); : } : } 可以試試改成以下這樣: function doCheck(num,int,dec){ var p = new RegExp("^\\d{1,"+int+"}$|^\\d{1,"+int+"}\\.\\d{1,"+dec+"}$"); if(p.exec(num)==null){ alert("不符合規定!"); }else{ alert("通過檢核!"); } } -- ...the people who are crazy enough to think they can change the world, are the ones who do... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.133.102.122
PTTFHK:酷~ 非常感謝你~^^*(但後來發現需將int改成其他非保留字) 03/10 09:51