You said you tried this:
But this does not look like a valid regexp. You should give regular expressions a little research to get a better hang on what you can do there. A good starting point would be MDN - RegExp
. There is a lot to learn in the regex world.
Once that part is sorted out, then there's the specific functionality. Here's the documentation entry: Ext.form.field.Text.MaskRe
And it says (or said at the time this post was being written):
An input mask regular expression that will be used to filter keystrokes (character being typed) that do not match. Note: It does not filter characters already in the input.
What this means? It does subject the immediate input character
to that regex filter, not what's in the field
. So at any time if your regexp matches more than one character, it will never be accepted as input in the field, as we can only type one character at a given time.
I believe the
config is not what you need in your case.
Option 1: event to handle change event
One option is to tie a change event to accept or not the field value
as it changes. You'd need to tie a state machine kind of event handler to the change event
, keydown event
, keypress event
, or the keyup event
(or any other event you may feel fit) to tie this logic to the text field.
Option 2: use a combo box to limit input
Alternatively, maybe easier and user-friendly option, would be to just use a combo box. You can use type-ahead
to let the combo box suggest possible values. If you can't see what I'm talking about, just take some time to browse our combo box component examples in Examples Explorer
Option 3: form validation
Another approach, that I believe that goes a bit away from your need, but would be probably the easiest to implement is form validation
. That's simply showing a red exclamation mark on your field when the input is not accepted. You can add a note besides the field to tell why it is invalid, alternatively show the message on mouse hover the exclamation, or just use a common place to leave the error explanation. Then only once the text field has valid input the "submit" or "save" buttons would be available.
Just in case, here's some form validation examples for you to browse: Examples matching "validation" in Examples Explorer
Hope this helps and one of the options is feasible. Not showing examples on the event as that is going to be a really custom code you would need to add to allow the input either in realtime (with the key related events), and similar to validation (option 3) if using change