Last active
November 21, 2024 13:39
-
-
Save utlime/52a1ac8bb2e2ece1efd20803e693673d to your computer and use it in GitHub Desktop.
Маска ввода для кадастрового номера (text-mask/cadastral-number)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TextMask.maskInput({ | |
inputElement: document.querySelector("input[name = cadastral_number]"), | |
mask: function(rawValue) { | |
var mask = [/\d/, /\d/, ":", /\d/, /\d/, ":"]; | |
var chunks = rawValue.replace(/\_/g, "").split(":"); | |
var i; | |
for (i = 0; (!chunks[2] || i < chunks[2].length) && i < 7; i++) { | |
mask.push(/\d/); | |
} | |
if (!chunks[3] && (!chunks[2] || chunks[2].length < 7)) { | |
mask.push(/\d|:/); | |
} else { | |
mask.push(":"); | |
} | |
for (i = 0; (!chunks[3] || i < chunks[3].length) && i < 20; i++) { | |
mask.push(/\d/); | |
} | |
return mask | |
}, | |
guide: false, | |
keepCharPositions: false, | |
showMask: false | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Чуть подредактировал, для использования с https://github.com/vuejs-tips/vue-the-mask и Vue 2
В компоненте: