javascript - Easiest way to mask characters in HTML(5) text input -
does html5 have kind of text field masking or still have trap onkeydown etc.?
jbabey right--"masking" in blocking illegal characters, not hiding what's typed.
the best (as in simplest , reliable) way i've found trap onkeyup , run regex replace on value of textfield, removing illegal characters.
this has few advantages:
- it's easy implement (one function, 2 lines of code).
- it's reliable , covers cases i've thought of.
- it doesn't block key commands copy/paste, select or arrow keys.
but major disadvantage shows typed character(s) briefly before removing them, makes hackish , unprofessional.
look new html5 input types. these instruct browsers perform client-side filtering of data, implementation incomplete across different browsers. pattern attribute regex-style filtering, but, again, browsers don't (or @ all) support it.
however, these won't block input itself, prevent submitting form invalid data. you'll still need trap onkeydown event block key input before displays on screen.
Comments
Post a Comment