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; }
});