UNPKG

jb-mobile-input

Version:
48 lines (47 loc) 2.01 kB
import { JBInputWebComponent as e } from "jb-input"; import { JBDictionary as t, i18n as i } from "jb-core/i18n"; const n = new t({ fa: { validNumberMessage: "شماره موبایل معتبر نیست" }, en: { validNumberMessage: "mobile number is not valid" } }); var o = class extends e { constructor() { super(), this.initMobileInputWebComponent(); } initMobileInputWebComponent() { const e = document.createElement("template"); e.innerHTML = "<style>:host{--input-direction:var(--jb-mobile-input-input-direction,ltr)}</style><style>.jb-input-web-component{--jb-input-input-direction:var(--input-direction)}</style>", this.shadowRoot.appendChild(e.content.cloneNode(!0)), this.validation.addValidationListGetter(this.#e.bind(this)), this.addStandardValueCallback(this.#t.bind(this)); } #e() { const e = [], t = { validator: /^(?:09[0-9]{2} [0-9]{7})?$/g, message: n.get(i, "validNumberMessage") }; return e.push(t), e; } #i(e) { const t = e.replace(/\s/g, "").replace(/\u06F0/g, "0").replace(/\u06F1/g, "1").replace(/\u06F2/g, "2").replace(/\u06F3/g, "3").replace(/\u06F4/g, "4").replace(/\u06F5/g, "5").replace(/\u06F6/g, "6").replace(/\u06F7/g, "7").replace(/\u06F8/g, "8").replace(/\u06F9/g, "9").replace(/[^0-9]/g, ""), i = /(?<opCode>(09|0|9)?)(?<number>.{0,})/g.exec(t); if (i && i.groups) { let e, t = i.groups.number; if (t = t.substring(0, 9), i.groups.opCode) e = "9" === i.groups.opCode ? "09" : i.groups.opCode; else { if (!(t.length > 0)) return ""; e = "09"; } return 1 == e.length ? e : e + t; } return ""; } #t(e) { let t = "", i = ""; i = this.#i(e); const n = /(09[0-9]{0,2})([0-9]{0,7})/g.exec(i); return t = n && n.length > 0 ? n.slice(1).filter((e) => "" !== e).join(" ") : i, { value: i, displayValue: t }; } }; customElements.get("jb-mobile-input") || window.customElements.define("jb-mobile-input", o); export { o as JBMobileInputWebComponent, n as dictionary }; //# sourceMappingURL=jb-mobile-input.js.map