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:

  1. it's easy implement (one function, 2 lines of code).
  2. it's reliable , covers cases i've thought of.
  3. 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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -