1. #11
    Sencha User
    Join Date
    Dec 2013
    Location
    Turkey
    Posts
    29
    Vote Rating
    -1
    FatihBekdemir is an unknown quantity at this point

      0  

    Default Prevent Special Characters

    Quote Originally Posted by mitchellsimoens View Post
    You can set the pattern attribute and even listen to keydown event. Here is an example I had to use for an app:

    Code:
    Ext.define('Ux.field.PatternText', {
        extend : 'Ext.field.Text',
        xtype  : 'patterntextfield',
    
        config : {
            pattern : '[0-9]*'
        },
    
        updatePattern : function(pattern) {
            var component = this.getComponent();
    
            component.updateFieldAttribute('pattern', pattern);
        },
    
        initialize : function() {
            this.callParent();
    
            var component = this.getComponent();
    
            component.input.on({
                scope   : this,
                keydown : 'onKeyDown'
            });
        },
    
        onKeyDown : function(e) {
            var code = e.browserEvent.keyCode;
    
            if (!(code >= 48 && code <= 57) && !(code >= 97 && code <= 105) && code !== 46 && code !== 8) {
                e.stopEvent();
            }
        }
    });
    You can of course make onKeyDown work for you, mine is a little verbose. It also stops copy paste

    Thanks mitchellsimoens , but is there any way to prevent special characters like ( ! & %) ?
    pattern : '[0-9]*' and keyCode's that you wrote is not working for special characters in Ext.field.Text Sencha touch.

    Thanks

  2. #12
    Sencha User
    Join Date
    Nov 2013
    Posts
    58
    Vote Rating
    0
    Answers
    1
    MarcoScherer is on a distinguished road

      0  

    Default

    Thanks for that example code. I extended it, but got issues with special chars like ä, ö, ü

    ä returns code 222 (although ascii tables list it with code 230)
    ' does also return code 222 (although ascii tables list it with code 39)

    ö returns code 186 (should be 156)
    : returns code 186 (should be 58)

    Same for some others keys. Is there any way to handle this?