Javascript Input Text Masking without Plugin

前端 未结 2 1376
星月不相逢
星月不相逢 2020-12-16 18:39

I want to mask the text in an input box without changing the actual value. I can not use any plugins.

I am currently doing this - but as you can see the issue is tha

2条回答
  •  一个人的身影
    2020-12-16 19:03

    or also

    
    

    with

    function handleMask(event, mask) {
        with (event) {
            stopPropagation()
            preventDefault()
            if (!charCode) return
            var c = String.fromCharCode(charCode)
            if (c.match(/\D/)) return
            with (target) {
                var val = value.substring(0, selectionStart) + c + value.substr(selectionEnd)
                var pos = selectionStart + 1
            }
        }
        var nan = count(val, /\D/, pos) // nan va calcolato prima di eliminare i separatori
        val = val.replace(/\D/g,'')
    
        var mask = mask.match(/^(\D*)(.+9)(\D*)$/)
        if (!mask) return // meglio exception?
        if (val.length > count(mask[2], /9/)) return
    
        for (var txt='', im=0, iv=0; im

提交回复
热议问题