input-masking icon indicating copy to clipboard operation
input-masking copied to clipboard

Autofill Special Characters

Open Auer111 opened this issue 4 years ago • 2 comments

After some testing I found some users found it unintuitive to only type numbers for masked dates. (they would try to type in the slashes). If there is some functionality I didn't understand that supports this in the docs let me know, otherwise I found this solution.

inside of handleCurrentValue after the for loop add

if (value.length < l) { if (placeholder[value.length].match(/\W/)) { newValue += placeholder[value.length]; } }

Example: 12/25 -> 12/25/

Auer111 avatar Dec 28 '20 14:12 Auer111

Found the solution above was a bit limiting so here is a new version with support for things like

XXABC-XXX

in handleCurrentValue var isCharsetPresent = e.target.getAttribute('data-charset'), placeholder = isCharsetPresent || e.target.getAttribute('data-placeholder'), value = e.target.value, l = placeholder.length, newValue = '', i, j, isInt, isLetter, strippedValue, regNot = new RegExp("[^"+this.opts.mNum+this.opts.mChar+"]");

and after the for loop if (newValue.length >= value.length) { for (i = newValue.length; i < l; i++) { if (placeholder[i].match(regNot)) { newValue += placeholder[i]; } else { break; } } }

Auer111 avatar Dec 28 '20 15:12 Auer111

This helped, thanks!

cepm-nate avatar Jul 14 '21 16:07 cepm-nate