The title of this article is something all XUL authors have always wanted and needed at some point. There's an old bug about it, a bug I missed. Yesterday, someone asked for that exact feature in #xulfr on irc.mozilla.org. I first started saying that adding an input event handler in textbox.xml performing a replace() is not hard. Then I remembered this is not all undo/redo-friendly. Then I also saw replace() FILTERS OUT characters matched by the regexp instead of PRESERVING ONLY the characters matched by the regexp, the behaviour originally requested in the bug and probably the more natural.

Since it's very easy to cancel a keypress event in the editor (just capture it before the editor and call preventDefault()), I wrote a very light patch adding the filter attribute and the filter property to a textbox.