1. 千位符:git
function formatMoney (number, places, symbol, thousand, decimal){ number = number || 0; //保留的小位數 能夠寫成 formatMoney(542986,3) 後面的是保留的小位數,不然默 認保留兩位 places = !isNaN(places = Math.abs(places)) ? places : 2; //symbol表示前面表示的標誌是¥ 能夠寫成 formatMoney(542986,2,"$") symbol = symbol !== undefined ? symbol : "¥"; //thousand表示每幾位用,隔開,是貨幣標識 thousand = thousand || ","; //decimal表示小數點 decimal = decimal || "."; //negative表示若是錢是負數有就顯示「-」若是不是負數 就不顯示負號 //i表示處理過的純數字 var negative = number < 0 ? "-" : ""; var i = parseInt(number = Math.abs(+number || 0), 10) + ""; console.log(i); var j = (j = i.length) > 3 ? j % 3 : 0; return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/\B(?=(\d{3})+(?!\d))/g, thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : ""); } console.log(formatMoney(1234567.1234,3));
http://www.javashuo.com/article/p-aqjsccbc-bp.html正則表達式
正則表達式的詳解。windows
1-2. JavaScriptAPI。post
var formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'JPY', //此處爲各貨幣的縮寫,如$USD、¥JPY,CAD,EUR,GBP等,都能展現對應的貨幣顯示 minimumFractionDigits: 2 }); console.log(formatter.format(12345.5556))//¥12,345.56
2. spa
/*是否帶有小數*/ function isDecimal(strValue ) { var objRegExp= /^\d+\.\d+$/; return objRegExp.test(strValue); } /*校驗是否中文名稱組成 */ function ischina(str) { var reg=/^[\u4E00-\u9FA5]{2,4}$/; /*定義驗證表達式*/ return reg.test(str); /*進行驗證*/ } /*校驗是否全由8位數字組成 */ function isStudentNo(str) { var reg=/^[0-9]{8}$/; /*定義驗證表達式*/ return reg.test(str); /*進行驗證*/ } /*校驗電話碼格式 */ function isTelCode(str) { var reg= /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/; return reg.test(str); } /*校驗郵件地址是否合法 */ function IsEmail(str) { var reg=/^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/; return reg.test(str); }
var
data =
'windows 98 is ok'
;
code
data.match(/windows (?=\d+)/);
// ["windows "]
data.match(/windows (?:\d+)/);
// ["windows 98"]
data.match(/windows (\d+)/);
// ["windows 98", "98"]