ElegantWM.WebUI/Application/common/src/Tools.js
歡迎大家貢獻更多的正則驗證規則,目前支援如下:
/*****************************************************************/ /* VType自定義校驗 */ /*****************************************************************/ Ext.apply(Ext.form.VTypes, { number: function (val, field) { return /^\d+$/.test(val); }, numberText: '只能輸入數字', mobilephone: function (val, field) { return /^1[3|4|5|6|7|8|9][0-9]{1}[0-9]{8}$/.test(val); }, mobilephoneText: '手機號碼格式錯誤', postcode: function (val, field) { return /^[1-9]\d{5}$/.test(val); }, postcodeText: '郵政編碼格式錯誤', idnum: function (val, field) { return /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(val); }, idnumText: '身份證格式錯誤', ipaddress: function (val, field) { return /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(val); }, ipaddressText: 'IP地址格式錯誤', amount: function (val, field) { return /^(([1-9]\d*)|\d)(\.\d{1,2})?$/.test(val); }, amountText: '金額格式錯誤', passwordConfirm: function (value, field) { if (!(field.confirmTo instanceof Ext.form.Field)) { field.confirmTo = Ext.getCmp(field.confirmTo); } return (value == field.confirmTo.getValue()); }, passwordConfirmText: '兩次新密碼輸入不一致',
//Extjs 4 DateField 日期區間驗證,From To
daterange: function (val, field) { var date = field.parseDate(val); if (!date) { return; } if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax .getTime()))) { var start = Ext.getCmp(field.startDateField); start.setMaxValue(date); start.validate(); this.dateRangeMax = date; } else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin .getTime()))) { var end = Ext.getCmp(field.endDateField); end.setMinValue(date); end.validate(); this.dateRangeMin = date; } /* * Always return true since we're only using this vtype to set * the min/max allowed values (these are tested for after the * vtype test) */ return true; }
});