UNPKG

@open-data-v/ui

Version:

OpenDataV UI基础包

66 lines (65 loc) 1.57 kB
const a = { digits: /^[0-9]*[1-9][0-9]*$/, // 正整数 number: /^\d+(\.\d+)?$/, // 带小数 mobile: /^1[3|4|5|7|8]\d{9}$/, // 手机 mail: /^[a-z0-9A-Z._%-]+@([a-z0-9A-Z-]+\.)+[a-zA-Z]{2,4}$/, tel: /^0\d{2,3}-\d{7,8}$/, // 电话020-00000 fax: /^(\d{3,4})?[-]?\d{7,8}$/ }; function c(e) { const n = Function; return new n("return " + e)(); } const r = function(e) { return /^\s*$/g.test(e); }, i = function(e, n, s) { return s === "rule" ? c(n).test(e) : a[n] === void 0 ? "undefined" : c(a[n]).test(e); }, o = function(e, n) { for (let s = 0, f = n.length; s < f; s++) { const t = n[s]; switch (t.type) { case "required": if (r(e) || e === !1) return t.msg; break; case "digits": case "number": case "mobile": case "mail": case "tel": case "fax": if (!r(e) && !i(e, t.type)) return t.msg; break; case "phone": if (!r(e) && !(i(e, "mobile") || i(e, "tel"))) return t.msg; break; case "maxLength": if (!r(e) && parseInt(e.length) > parseInt(t.len)) return t.msg; break; case "minLength": if (!r(e) && parseInt(e.length) < parseInt(t.len)) return t.msg; break; case "rule": if (!r(e) && !i(e, t.rule, "rule")) return t.msg; break; case "fn": if (!t.validator(e)) return t.msg; break; } } return !0; }; export { o as default }; //# sourceMappingURL=validate.esm.js.map