function ParseJsonDate(jsonDate) { ///將Json日期格式轉換為一般日期字串 /// Json日期格式的字串 var date = new Date(parseInt(jsonDate.substr(6))); return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate(); }
//此為JQuery UI的日期選取器 原為英文格式 改為中文版加上修改日期格式
function SetDateTimePicker(control) { ///設定日期選取器 /// 使用JQuery Selector選取的物件 control.datepicker({ dateFormat: "yy/mm/dd", changeYear: true, changeMonth: true, defaultDate: 0, dayNames: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"], dayNamesMin: ["日", "一", "二", "三", "四", "五", "六"], dayNamesShort: ["日", "一", "二", "三", "四", "五", "六"], monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"] }); }
//驗證身份證字號
function checkID(id) { ///驗證身份證字號是否符合格式 /// 身份證字號 tab = "ABCDEFGHJKLMNPQRSTUVXYWZIO" A1 = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3); A2 = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5); Mx = new Array(9, 8, 7, 6, 5, 4, 3, 2, 1, 1); if (id.length != 10) return false; i = tab.indexOf(id.charAt(0)); if (i == -1) return false; sum = A1[i] + A2[i] * 9; for (i = 1; i < 10; i++) { v = parseInt(id.charAt(i)); if (isNaN(v)) return false; sum = sum + v * Mx[i]; } if (sum % 10 != 0) return false; return true; }
//使用正規表達式驗證是否為數字
function isNumber(val) { ///驗證是否為數字格式 /// 要驗證的值 var reg = /^[0-9]*$/; return reg.test(val); }
//只能輸入數字
function keyNumber(e, val) { ///此欄位只能輸入數字 if (!/^\d+$/.test(val)) { var newValue = /^\d+/.exec(e.value); if (newValue != null) { e.value = newValue; } else { e.value = ""; } } return false; }
//文字補零
function padLeft(str, length) { ///在文字的左邊補0至固定長度 /// 要補0的文字 /// 需要的文字長度 if (str.length >= length) return str; else return padLeft("0" + str, length); }