jb-mobile-input
Version:
mobile input web component
54 lines (53 loc) • 2.43 kB
JavaScript
(function(e, t) {
"object" == typeof exports && "undefined" != typeof module ? t(exports, require("jb-input"), require("jb-core/i18n")) : "function" == typeof define && define.amd ? define([
"exports",
"jb-input",
"jb-core/i18n"
], t) : t((e = "undefined" != typeof globalThis ? globalThis : e || self).JBMobileInput = {}, e.JBInput, e.JBCoreI18N);
})(this, function(e, t, n) {
Object.defineProperty(e, Symbol.toStringTag, { value: "Module" });
const i = new n.JBDictionary({
fa: { validNumberMessage: "شماره موبایل معتبر نیست" },
en: { validNumberMessage: "mobile number is not valid" }
});
var o = class extends t.JBInputWebComponent {
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: i.get(n.i18n, "validNumberMessage")
};
return e.push(t), e;
}
#n(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, ""), n = /(?<opCode>(09|0|9)?)(?<number>.{0,})/g.exec(t);
if (n && n.groups) {
let e, t = n.groups.number;
if (t = t.substring(0, 9), n.groups.opCode) e = "9" === n.groups.opCode ? "09" : n.groups.opCode;
else {
if (!(t.length > 0)) return "";
e = "09";
}
return 1 == e.length ? e : e + t;
}
return "";
}
#t(e) {
let t = "", n = "";
n = this.#n(e);
const i = /(09[0-9]{0,2})([0-9]{0,7})/g.exec(n);
return t = i && i.length > 0 ? i.slice(1).filter((e) => "" !== e).join(" ") : n, {
value: n,
displayValue: t
};
}
};
customElements.get("jb-mobile-input") || window.customElements.define("jb-mobile-input", o), e.JBMobileInputWebComponent = o, e.dictionary = i;
});
//# sourceMappingURL=jb-mobile-input.umd.js.map